Back up with time stamp

My wife is constantly reminding me that “technology will always fail you” and she’s right. Muphy’s law states that if anything can go bad, it will! As far as I can remember I’ve had hard drives die on me, and that is why I always backup everything. On top of backing up everything I always test my backups, if you don’t test your backups it’s sort of like you never did a backup in the first place.
hard drive
Creating backups has been a big part of my life.

here is a script to backup all MySQL Databases to individual files

for I in $(mysql -p -e 'show databases' -s --skip-column-names);
do mysqldump -p $I | gzip > "/var/www/mysqlbackups/$I.sql.gz"; done

Here is a simple one liner to back up everything in your www folder to a mounted hard drive on /mnt/sdb5

tar zcvf /mnt/sdb5/backups/backup$(date '+%F_%H%I%S%P').tar.gz /var/www  
-z, --gzip "filter the archive through gzip"

-c, --create "create a new archive"
-v, --verbose "verbosely list files processed"
-f, --file=ARCHIVE "use archive file or device ARCHIVE"
/mnt/sdb5/backups/backup$(date '+%F_%H%I%S%P').tar.gz "location with time stamp"
/var/www "folder backup"
combine these 2 one-liners and you have your self a pretty good backup.

all that's left to is add the lines to a cron job run the mysql one-liner at 11:30 and run the /var/www backup at midnight.

Tagged . Bookmark the permalink.

2 Responses to Back up with time stamp

  1. Pingback: Tweets that mention Back up with time stamp -- Topsy.com

  2. Pingback: Quickies: time stamped backups « 0ddn1x: tricks with *nix

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>