Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.


share|improve this question
Take a look at my script:… – Florin Andrei Feb 12 '14 at 21:12

4 Answers 4

Look at these tools:

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.

share|improve this answer

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.

share|improve this answer
The OP uses the word "folders" which implies that the backups would be on-line (on the same media or system) which makes the backups almost completely (but not quite totally) useless. OK, in the worst case scenario - completely useless. By the way, you forgot to mention rsync (and dd has its uses, too). +1 for the emphasis on restoring. It should be pointed out that the restores must be tested. – Dennis Williamson Aug 12 '10 at 14:10

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

#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


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
share|improve this answer

You can use Duplicity for that purpose. Compared to the popular rsnapshot and rdiff-backup it is still actively developed.

The only pitfall is that you can't create daily, weekly and montly backups but it's possible to create a simpler combination like "daily, weekly" or "weekly, monthly" or "daily, monthly" and so on.

For this I recommend this wrapper script: which simplifies the configuration significantly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.