What kind of backups are available?

Would it be possible for me to take a sort of profile/user backup? I may need to format my HD and reinstall OpenSUSE but I don’t want to have configure and install everything again. Can all that stuff be backed up and restored onto a fresh system?

Thanks

Hi Astralogic,

If you /home directory is in a dedicated partition, you can install openSUSE without formatting it (but personnaly I would make a backup just in case). But if you need to format all your hard drive, you can easily make a backup of the current user profile using any archive and backup tool. Using good old tar:


/$ tar --one-file-system -cWf *backupFilePath* "$HOME" --exclude="$HOME/.cache"

Where backupFilePath is where you want the TAR archive to be created. I don’t think you want to backup your applications’ cache, this why the folder .cache in your home directory is excluded. In order to this command line to succeed, you should run it from the root of your file-system (/) otherwise tar will not be able to check files have been successfully backed up.

Your /home partition has all your user settings but, if you have made changes to system files, they are likely to be in /etc and, if you are using mysql, you should back it up with mysqldump - I simply back up the relevant files to /home and then they are backed up when I back up /home.

Will this backup include the shortcuts to new programs in the K menu? I don’'t mind redoing the odd system setting or two.

Also what would be the command to restore the backup?

Do you mean manually created shortcuts?
Those are stored in /home, yes. (~/.local/share/applications/)

The standard shortcuts get created when you install the corresponding applications, so no need to backup those.

As wolfi323 said, a backup a your home directory will contain the application shortcuts created manually because they are stored in your home directory.

The command line to restore the backup would be something like:


/# tar -xf *backupFilePath*

You may need to change the owner of the restored home directory using chown if your new user doesn’t have the same uid than the old one.

Thanks for the info. I just found KBackup, it’s basically exactly what you describe here, files being backed up with TAR except it takes care of all the commands.

I’ve looked up the chown command, it seems simple but let me see if I have it right. My login name is ‘calvin’ I just type "chown calvin “$HOME” right?.

But what if after formatting and reinstalling I use the same name, I wouldn’t need to change the owner correct? Because they’d be the same.

Nearly.
Add the -R option, to recursively change all files in all subdirectories as well, and probably you would have to do it as root:

sudo chown -R calvin /home/calvin

But what if after formatting and reinstalling I use the same name, I wouldn’t need to change the owner correct? Because they’d be the same.

The owner is stored as a number internally, so the name doesn’t actually matter.
If there’s only one user in either case, the id should stay the same.

The user name DOES matter for the name of the home directory of course.
So if you use “calvin2” as user name on the new install f.e., your home directory would be named /home/calvin2 instead of /home/calvin.
You maybe have to consider this when restoring the backup.

I just realized that I’'m not sure what the file path should be. The home folder that gets backed up isn’t the actual folder called home is it? It’s the folder with my user name which is inside the home folder. So it should be restored to /home. Is that right?

backupFilePath* is the path to the tar archive which contains the backup of your former home folder. This tar archive may have been created using the command line given in post #2, recalled bellow for convenience:


/$ tar --one-file-system -cWf *backupFilePath* "$HOME" --exclude="$HOME/.cache"

A typical use case would be Tux wanting to backup up his home folder before re-installing openSUSE. First, he creates a tar archive containing all his data in an external hard drive partition called myHardDrive. The partition myHardDrive has been mounted to /run/media/tux/myHardDrive.


/$ tar --one-file-system -cWf /run/media/tux/myHardDrive/backup.tar /home/tux --exclude=/home/tux/.cache

The resulting size of /run/media/tux/myHardDrive/backup.tar should be very close to the size of /home/tux.

GNU tar implementation removes by default the leading / of tar archive members’ path. So, if Tux had a file in his home folder which path was /home/tux/letter.txt, it would be stored in /run/media/tux/myHardDrive/backup.tar as home/tux/letter.txt. This is an important point to remember when restoring from a tar archive.

Tux as finished to re-install openSUSE and have created a temporary user backupagent in order to restore his data with an unprivileged user. Using YaST he creates a new user called tux. He plugs in his external hard drive and mounts the myHardDrive partition to /run/media/backupagent/myHardDrive. He wants his former tux home folder to be restored in /home/tux, where the new tux home folder lies. Remembering that the leading / has been removed inside the tar archive, he needs to extract the contents of the tar archive from the root of the filesystem /:


**/**# tar -xf /run/media/backupagent/myHardDrive/backup.tar

He runs the command as root so the permissions and ownership of his former home folder are also restored. Eventualy, he checks the ownership and permissions of /home/tux using ls:


$ ls -l /home/tux

He see that /home/tux is owned by tux user and is assigned to users group. If it was otherwise, he could have corrected the ownership using chown:


# chown -R tux:users /home/tux

I hope this use case made it clearer how tar can be used for backing up and restoring data. If you choose to take this use case as an example, please check the command lines before executing them. Chiefly those executed as root.

Guys, it’s not working :frowning:

http://susepaste.org/38903792

What happened?

There are 3 problems with your tar command:

  1. The path to your external disk contains a space, so you have to put it in quotation marks. Since you didn’t do that, tar will have created a file called “/run/media/calvin/2TB”.
  2. You gave only the path of a directory, but you need to give a file name as well. E. g. “/run/media/calvin/2TB Storage/Backups/backup.tar”
  3. Did you run that command as root? It looks as if you did. You need run it as normal user. Otherwise “$HOME” will equal “/root” and you will backup that instead of your home.

Correct command would be:


tar --one-file-system -cWf "/run/media/calvin/2TB Storage/Backups/backup.tar" "$HOME" --exclude="$HOME/.cache"

Yeah I did it as root but, I still get errors:

http://susepaste.org/81792195

I think the backup worked fine, but all those errors are about the verification:


tar: Removing leading `/' from member names
tar: Archive contains file names with leading prefixes removed.
tar: Verification may fail to locate original files.

tar can’t locate the original files, because it looks for them in and current directory, and that is /home/calvin. Change to the root directory (/) before running tar and it should work.


cd /
tar --one-file-system -cWf "/run/media/calvin/2TB Storage/Backups/backup.tar" "$HOME" --exclude="$HOME/.cache"

I thought I could add a -j to compress with bzip2 but it’s not working:

tar --one-file-system -cWfj "/run/media/calvin/2TB Storage/Backups/Linux/home.tar" "$HOME" --exclude="$HOME/.cache"
tar: Removing leading `/' from member names
tar: /run/media/calvin/2TB Storage/Backups/Linux/home.tar: Cannot stat: No such file or directory
tar: Archive contains file names with leading prefixes removed.
tar: Verification may fail to locate original files.
tar: Exiting with failure status due to previous errors

:frowning:

You’re right, basically. But the -f option expects the name of the archive file as a parameter, so you can’t use another option after -f. Use -cWjf and it will work.