Setup Backup

Posted on Sunday March 13, 2016 / by Eric Potvin

Every system should have backups. In case of emergency, backup are very useful. Your backup can save you hours of down time with a minimum impact.

There's is some tools you can use to backup your entire system or your most important files. tar, gzip, bzip2, dump and rsync are some tools you can use to backup files and folders. automysqlbackup is a tool to backup your MySQL databases.

Example backup

Here's an example of a folder backup including all the sub-folders and files within.

tar -cvf archive-name.tar dir1 dir2 dir3....

Now, let's compress it:

gzip -9 archive-name.tar

You can use bzip2 instead. bzip2 has a better compression rate but is a little slower.

To combine both command, you can use the -z option.

dump

dump is written specifically for backups. It backs up the entire file system and allows multiple levels of backups. The corresponding restore command allows for restore from a dump backup.

For example, to backup /boot file system:

dump 0zf backup.boot /boot

Backup MySQL

There's an easy command to backup MySQL databases. automysqlbackup can automatically make daily, weekly, and monthly backups of your MySQL database.

Install

sudo aptitude install automysqlbackup

Configure Backup

sudo vi /etc/default/automysqlbackup

All the backup are stored in the /var/lib/automysqlbackup by default. It is recommended to change this folder. To change the default backup folder, edit the file and modify the BACKUPDIR= to the new location.

You can also receive an email if there's an error while running the backup. To do this, you need to change the MAILADDR= and add your email address.

Backup Home Folder

You can backup your entire home folder using the zip command. If you want to exclude some folder, you need to use the --exclude parameter.

zip -r myzipbackup.zip  * --exclude=access_log --exclude=public_ftp --exclude=tmp