Backup

From LQWiki
(Redirected from Backups)
Jump to navigation Jump to search

Backups are part of a sane recovery scheme that should help recover lost data. They can be thought of anything that is done to archive important system and user data.

Backup strategies

For home users

Keep a folder with files that you want to keep secure. You need to copy it to another disk so the data survives when one disk fails or you delete something by accident. Best, have your archive folder on your hard disk and copy it to at least one USB disk. Now you need software to synchronize this folder on the two disks. A good choice is UnisOn. It allows you to sync bidirectionally, and it compares the files' content rather than their change date. This allows you to identify corrupted files.

How to do it

Backup your home directory

From the command line, type:

tar -cvzf myhomebackup.tar.gz ~

~ stands for your home directory. The z option packs your file in gzip format.

Then copy myhomebackup.tar.gz onto some other medium: CD, DVD, removable drive, etc.

Hint: Using tar with the --newer option will allow you to save only files that have changed since your last backup. This is known as incremental backup, compare rsync.

Backup your computer

To backup your computer including all system configuration and kernel modules, but excluding everything that is mounted (e.g. /proc) use

tar -cvlf slash.tar.gz /

The l option says "local filesystems only". You need it because you do not want to backup /proc.

To store a backup of your computer on another computer in the network, use

tar -cv -f- $(ls -1 | grep -Ev "proc|sys|tmp|media|mnt") | ssh root@target "cat >/root/slash.tar"

This stores a backup of your computer, but not /proc, /sys, /tmp, /media and /mnt on the computer target in /root/slash.tar.

Backup and synchronise several computers

If you have several computers (maybe because you have several flats), you can maintain an eternal archive on a USB disk that you can transport. For data security, you synchronize your USB disk with your computers. Let's say the USB disk is mounted on /mnt/sda1, and your archive is in /root/archive. You create your archive with

rsync -e ssh -avz /root/archive /mnt/sda1

You can then show the differences between your archive on a USB disk and on your computer with

rsync -e ssh -avz --delete --dry-run /mnt/sda1/archive /root/archive

And you can update your computer's archive from a USB disk using

rsync -e ssh -avz /mnt/sda1/archive /root/archive

You can add the --delete option behind -avz to delete all content on the target that is not on the source. If you are using HOWTO Create ssh keys with rsync as a different user

rsync -avz /path/to/local/file -e 'ssh -i /home/user/.ssh/id_rsa' remote_user@remote_system:/path/to/remote/

Same process on a non-standard port

rsync -avz /path/to/local/file -e 'ssh -p22222 -i /home/user/.ssh/id_rsa' remote_user@remote_system:/path/to/remote/

Backup MySQL

See MySQL Backup Procedure.

Backup utilities

See list of backup applications.

See also