Home Wiki > SDB:Home backup
Sign up | Login

SDB:Home backup

tagline: From openSUSE


This article explains how to back up your /home, and the various tools you can use to perform this backup.

Backup your /home

When /home directory is on a standalone partition then very few things can go wrong, but it is always a good idea to create a backup.

What to backup

Find if /home has its own Partition

To find out if your home is on its own partition you can use df like this

df -h | grep /home

If the result is similar to this

/dev/sda4             122G  8.7G  107G   8% /home

then it is mounted in its own partition. Note that in case you want to backup the space you need on the backup media is the number shown in the second column (8.7G here).

If you dont get anything as a result of the last command then it is a directory under / and you should take a backup to an external medium.

How to find the size of /home if its under /

Dolphin - Dir Properties

You can either visit /home using your file manager (Konqueror/Dolphin/Nautilus) and right click on the directory and select properties or use the terminal and type

du -sh /home/

The result will look similar to this

8.5G    /home/

Special care should be taken in case you have windows or another distro installed and you mounted it under /home/windows in this case this will be counted also as well as all the other user homes. You can give du the exact path you want counted, for example if your username is openSUSE then you should type this in the terminal

du -sh /home/openSUSE

The result will look similar to this

8.5G    /home/openSUSE/


Backup Procedures

tar

You can create a compressed tar file with a full backup of your home directory using the following

Instead of gunzip you can use bzip2 which has a better compression ratio by substituting z with j as a parameter in the following commands. If you use bzip2 then also make sure to change the extension of the backup files to .tbz instead of .tgz so that you can remember latter what compression you used.


Backup

This will create a backup of user openSUSE in a file called myBackup.tgz inside the /home directory.

sudo tar cpzvf /home/myBackup.tgz --same-owner /home/openSUSE/

Incremental Backup

At a latter time you can add new files to your backup using the following

sudo tar cvzpnf /home/myBackup.tgz --same-owner /home/openSUSE/

Compare / Verify

After the backup you can do a compare of the backed up files using the following

tar tzvf /home/myBackup.tgz -C /home/openSUSE/

Restore

To restore the backed up files use the following

sudo tar zxvf /home/temp.tgz -C /


rsync

dd

If your /home is in a dedicated partition you can do a bit by bit copy (clone) using dd, you can either clone the partition to another partition or create an image of it and restore it latter.

You have to unmount the partition you are going to copy from and copy to

Make sure the target partition is at least the same size as the source one


Partition Cloning

To copy the /home partition to another partition as root type

dd if=/dev/sda4 of=/dev/sdb2


Partition Image

To copy the /home partition to a file, type

dd if=/dev/sda4 of=/yourFilename.dd

To restore the partition from the file, type

dd if=/yourFilename.dd of=/dev/sda4


Partition Image with Compression (gzip) and Split

The following will create 650MB gzip compressed files of the disk

dd if=/dev/sda4 | gzip -c | split -b 650m - homedisk.dd.gz_

To restore use the following

cat homedisk.dd.gz_* | gzip -dc | dd of=/dev/hda4


Backup Software

Bacula

rsync

Mondo Rescue

Amanda

Box Backup