====== Backups ====== Backing up your system, applications and documents is a life saver, and if you think you're immune to this kind of trouble, someday you'll learn the hard way! To avoid this hurdle many solutions are available, the whole thing being to choose the one that best fits your needs. What you'll find here is a combination of two complementary solutions. The first one aiming at offering the possibility to "flashback" your whole system to a certain configuration, the second one aiming at giving you the peace of mind to know that, even if you don't think about it, you'll be able to retrieve any document you ever created, at any stage you updated it since its creation! ===== "Snapshot" Method ===== The point here will be to create an exact copy of any of your partitions. It might be important to have such a copy to restore your system to a previous, stable, state in case it should become unstable after installing or tweaking something. ==== Foreword ==== At this point it becomes important to know what option you chose during your system installation. If you went for the "basic" installation, i.e. a single big partition of your hard disk drive holding your system as well as your documents, or if you opted for a more subtle partitioning scheme, at least separating your "/home" directory from the rest of the system files. In the first case, one single partition, the flashback method forces you to reset **everything** to a previously saved state. That involves your system as well as your saved documents. This, by itself, should push you to choose a partitioning scheme that, at least, separates your system files from your "/home" working directory. That means it is strongly recommend that you create a separate partition for your "/home" directory at install time. To learn more about the subject, please refer to the [[install:disk-partition|Disk Partitionning]] section of this wiki. ----- ==== FSArchiver ==== FSArchiver is a system tool that allows you to save the contents of a file-system to a compressed archive file. The file-system can be restored on a partition which has a different size and it can be restored on a different file-system. Unlike tar/dar, FSArchiver also creates the file-system when it extracts the data to partitions. Everything is checksummed in the archive in order to protect the data. If the archive is corrupt, you just loose the current file, not the whole archive === SystemRescueCD === You can easily create a bootable SystemRescueCD USB key using [[Liveusb Install]]. Once booted from the SystemRerqcueCD, first setup your network using <code> net-setup eth0 </code> Then start the nfsmount service using: <code> /etc/init.d/nfsmount start </code> It's now possible to access NFS shares on the network!\\ Prior to mounting one, you'll need to create a mount point for it, then mount it: <code> mkdir -p /mnt/nfs/nfs_share01 mount -t nfs 192.168.0.200:/volume1/nfs_share /mnt/nfs/nfs_share01 </code> If you would like to know how to setup the NFS server, you could start with [[http://sasikumarp.wordpress.com/how-to-take-backup-of-a-working-system-using-system-rescue-cd/|this guide]]. You can use fsarchiver to create a backup of your partitions: <code> fsarchiver -v savefs /mnt/nfs/nfs_share01/sdb2.fsa /dev/sdb2 </code> To learn more about the fsarchiver command, you can refer to it's [[http://www.fsarchiver.org/QuickStart|Quick Start Guide]] ----- ===== Synchronizing ===== ==== rsync ==== rsync is a very useful, and powerful, command that allows to (remote) synchronize directories of your choice. It can even be automated, using cron jobs for example, to provide an automated, incremental backup of your system. I'll complete this wiki when I get to this later, for the moment let's //simply// create a backup of our /home directory using rsync. === Some Advantages and Features of the rsync Command === * It efficiently copies and sync files to or from a remote system. * Supports copying links, devices, owners, groups and permissions. * It’s faster than scp (Secure Copy) because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination. * Rsync consumes less bandwidth as it uses compression and decompression method while sending and receiving data both ends. Basic syntax of rsync command <code> rsync options source destination </code> Some common options used with rsync commands * -v : verbose * -r : copies data recursively (but don’t preserve timestamps and permission while transferring data * -a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps * -z : compress file data * -h : human-readable, output numbers in a human-readable format === Directory Backup === You could use a command of this type to sync your /home directory, or any other one for that matter, to a local device: <code> rsync -avxzh --delete --stats --progress /home/ /mnt/nfs_share/backup/home </code> Options here are: * -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) * -v, --verbose increase verbosity * -x, --one-file-system don’t cross filesystem boundaries * -z, --compress compress file data during the transfer * -h, --human-readable output numbers in a human-readable format * --delete delete extraneous files from dest dirs * --stats give some file-transfer stats * --progress show progress during transfer Note the "/" at the end at the source path. It means that all elements **within** the /home/ directory will be copied to /mnt/nfs_share/backup/home, omitting the last "/" would copy the directory itself to the destination path. In case you'd like to access system files for backup, you have to run the command as sudo: <code> sudo -avxzh --delete --stats --progress / /mnt/nfs_share/backup/201312151555 </code> --------------------------------- ===== For the Record ===== **Advantages:** * Simple and straightforward * Relatively fast compared to other methods * Only way to "flashback" your whole system to a saved stable state **Disadvantages:** * Backup image requires the full space of the original partition * Files cannot be directly accessed within the backup image * Impossible to restore image to a smaller partition