2

I used the following alias to back up my root directory on Ubuntu 22.04 LTS to an external flash drive

alias backup='sudo rsync -aAXHS --info=progress2 --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*", "/USBDrive", "/lost+found"} / /USBDrive && notify-send -t 10000 "Backup complete"'

The file system on my usb drive is ext4.

I realize this probably isn't the best way but I was running into some issues and needed to reinstall to see if I could correct the issues.

I came across the following articles and will probably try them in the future as they appear much easier

Copy the entire root directory (/) for transferring OS to new computer?

Backup and restore of root file system (Ubuntu 20.04)

So my question is, what is recommended with the backup I have currently? From what I've read, it looks like a lot of hassle to restore the root directory. Unless someone knows of a fairly easy way to do so, I think I'll just restore the home directory. I'm looking for a way to backup and restore the home directory on any linux distribution (preferably without having to install anything else: this was the motivation for using the rsync command). Is it really just as easy as reversing the source and destination in the rsync command to restore after reinstalling the same OS on the same computer and what if I'm transferring to a new distribution that doesn't have the same parent, e.g. Debian vs Arch Linux? I also have git repositories that I cloned to my home directory. I'm not sure if this makes any difference and if this is normal practice with repositories. I'm also unsure if I will retain the packages installed with apt package manager from my backup if restoring on Ubuntu 22.04 LTS.

Update:

roaima's answer worked for me using a live disk after mounting the target disk. This didn't retain the packages installed with the apt package manager but I expected this. Therefore, you will have to rebuild programs from git repositories. If moving to another OS with a different parent, ex. Arch Linux, the root directory tree is different so I'm not sure if you're restoring more than the home directory.

1

1 Answer 1

2

The backup command was missing --numeric-ids but since you're only copying locally it probably doesn't matter.

To restore the backup you swap the source and destination arguments. Remember the --dry-run option while testing.

You can choose to restore just your home directory. Ensure once the copy is complete that the owner and group are correct (you installed a new OS so we shouldn't assume the target user's uid and gid are the same as in the backup)

find /home/whoever -user 12345 -exec chown newuser {} +
find /home/whoever -group 12345 -exec chgrp newgroup {} +
1
  • Looks good. I will likely try this soon after I decide on a distribution Apr 5 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .