Post

Linux Backups

Backup-daily

1
2
3
4
5
6
cat <<EOF >> /home/"$USER"/backup-task/backup-daily.sh
#!/bin/bash
tar --exclude=<path to ignore file> -zcf /home/"$USER"/backup/daily/backup-\$(date +%Y%m%d).tar.gz -C /home/"$USER"/<BackupFolder>/*
find /home/"$USER"/backup/daily/* -mtime +7 -delete
EOF
chmod +x /home/"$USER"/backup-task/backup-daily.sh

Backup-weekly

1
2
3
4
5
6
cat <<EOF >> /home/"$USER"/backup-task/backup-weekly.sh
#!/bin/bash
tar --exclude=<ignore file> -zcf /home/"$USER"/backup/weekly/backup-\$(date +%Y%m%d).tar.gz -C /home/"$USER"/<BackupFolder>/*
find /home/"$USER"/backup/weekly/* -mtime +31 -delete
EOF
chmod +x /home/"$USER"/backup-task/backup-weekly.sh

Backup-monthly

1
2
3
4
5
6
cat <<EOF >> /home/"$USER"/backup-task/backup-monthly.sh
#!/bin/bash
tar --exclude=<ignore file> -zcf /home/"$USER"/backup/monthly/backup-\$(date +%Y%m%d).tar.gz -C /home/"$USER"/<BackupFolder>/*
find /home/"$USER"/backup/monthly/* -mtime +365 -delete
EOF
chmod +x /home/"$USER"/backup-task/backup-monthly.sh

Add Chrontab task

1
2
3
4
5
6
cat <<EOF >> /etc/cron.d/crontask 
30 5 * * * root    /home/"$USER"/backup-task/backup-daily.sh 
40 5 * * 1 root    /home/"$USER"/backup-task/backup-weekly.sh 
50 5 1 * * root    /home/"$USER"/backup-task/backup-monthly.sh 
EOF 
crontab -u "$USER" /etc/cron.d/crontask
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.