Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering if someone could give me a quick script that I could run via cron that would backup my entire /var/www directory? I just want it to run once a day at 3:05am, and to put the copy in /media/sadisa/a_backup/engine/ . It'd be great if it could rename it to the time, like /media/sadisa/a_backup/engine/20100818_0305/www or something like that, but just www(1) www(2), etc would also work.

Thanks so much!

  • Josh
share|improve this question

migrated from Aug 19 '10 at 2:17

This question came from our site for professional and enthusiast programmers.

Check out – paxdiablo Aug 18 '10 at 21:56
up vote 2 down vote accepted

tarball with gzip-compression:

tar czf /media/sadisa/a_backup/engine/`date +%F`/var-www-`date +%F`.tgz /var/www/

Plain files & folders:

mkdir /media/sadisa/a_backup/engine/`date +%F`/
cp -a /var/www/ /media/sadisa/a_backup/engine/`date +%F`/var-www-`date +%F`
share|improve this answer

No need to reinvent the wheel.

Use duplicity.

share|improve this answer

Use proper backup software to do the trick. I use BackupPC, which works really well. Very configurable.

share|improve this answer
DATE_HASH = $(echo -n `date` | openssl md5)
tar cvzf backup.tgz /var/www/
mv backup.tgz /backup_folder/${DATE_HASH}.tgz

Edit: I clearly don't remember why I wrote that part. Update as recommended in the comments:

BACKUP_DATETIME=$(echo -n $(date +%Y%m%d_%H%M))
tar cvzf backup.tgz /var/www/
mv backup.tgz /backup_folder/${BACKUP_DATETIME}.tgz
share|improve this answer
No spaces around the equal sign. Why not use a human readable date? Why not use $() within $() instead of backticks? – Dennis Williamson Aug 19 '10 at 0:49
That wasn't a date hash - it's YYYYMMDD_HHMM which you can get date to print with the format argument. The reason he's doing that is cause it's sortable without jumping thru hoops. – hotei Aug 19 '10 at 2:36
That wasn't a date hash - it's date +%Y%m%d_%H%M . The reason he's doing that is cause it's sortable without jumping thru hoops. – hotei Aug 19 '10 at 2:41
I don't unterstand, why you do that "echo date | openssl md5"? Coul'd you explain it? – agporwfnz29 Aug 19 '10 at 6:35
How about: DATE_HASH = $(echo -n date +%Y%m%d_%H%M) ... and maybe a better name than DATE_HASH since it is no longer a hash... :) – Johan Aug 19 '10 at 6:52

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.