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
link|improve this question

Check out ubuntu.stackexchange.com – paxdiablo Aug 18 '10 at 21:56
feedback

migrated from stackoverflow.com Aug 19 '10 at 2:17

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

4 Answers

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`
link|improve this answer
feedback

No need to reinvent the wheel.

Use duplicity.

link|improve this answer
feedback

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

link|improve this answer
feedback
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
link|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? – bytesum 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
feedback

Your Answer

 
or
required, but never shown

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