daily, weekly, yearly backup script [closed]

Anyone has any bash script that does a daily/weekly/yearly backup script that I can use with cron.

Basically it will put the backups into 3 folders. Daily backup would only have this week's backup files. Weekly backup would only have this month's weekly backup file and month backup folder would yearly backup file.

Thanks!


Solution 1:

Look at these tools:

  • rsnapshot
  • rdiff-backup
  • bacula
  • amanda
  • dirvish
  • duplicity

You might find that these tools satisfy the requirements and eliminate your need for scripts. I use scripts also but they are for particular situations. If you want examples of what other people have done, two people have posted their backup scripts here.

Backups have been covered exhaustively on ServerFault. If you are trying to develop a backup strategy, I suggest searching the site. If you are unable to find a particular question answered, you might ask that in a separate question.

Solution 2:

No - but its very trivial to do. OTOH its far from trivial to provide an answer to your question based on the information you have suplied.

Certainly, it'd be a lot simpler to control the backup type (daily/weekly/yearly) and destination from the crontab rather than the bash script (although that might simply be a matter of sending a different parameter to the has script).

Backups are not intrinsically important - being able to restore your data is very important - so for your backup to have any value then it must be in a format which allows you to restore it. We can't tell you:

1) Which backup format is appropriate for your data
2) what backup tools you have on your system which are scriptable
3) what restore tools you are likely to have access to if you suffer a complete system failure
4) whether you need to support multi-volume / media changes in your backup

e.g. tar and compress are almost universally available - but its not very robust. CPIO is more robust but doesn't incorporate compression support.

Solution 3:

Warning: Hacked together in 5 minutes and untested (I don't have Bash installed).

#!/bin/bash
#Usage: $0 [Yearly,Monthly,Weekly]

set PROTECTEDFILES = "/etc /usr/home /usr/local/etc"
set BACKUPDIR = "/usr/backups"
set BACKUPTAR = backup-`hostname -s`-`date "+%F"`.tgz

tar czf $BACKUPDIR/$1/$BAKCUPTAR $PROTECTEDFILES

In crontab:

0   0   1   1   *   root   /root/sbin/my_backup Yearly
0   0   1   *   *   root   /root/sbin/my_backup Monthly
0   0   *   *   6   root   /root/sbin/my_backup Weekly