How to backup /home partition from one laptop and restore to another
On my current laptop, I have installed the /home in a separate partition, in the case I need to reinstall the OS, without having to backup and restore files and configurations.
My laptop is having hardware issues and my company bought me another, how can I backup the /home partition on the old laptop and restore to the new one?
Solution 1:
It is a matter of copying all files in the home directory, including the hidden files, while preserving linux file permissions (at least for the configuration files). Once the copy is made, check the ownership. If the user/group on the new system has a different UID than on the old system, you will need to adjust user and group ownerships.
I would be using rsync
for that, but also cp
is possible with the appropriate options set to preserve file properties. edit User Raj posted yet a third possibility using tar
. An advantage is that this third method does not require that the target drive supports linux file permissions.
If this sounds difficult and exceeds your technical skills, then consider just copying your personal user data. That data is personal and not replacable. Hence it is the most valuable. You can then just reconfigure your new system where needed as you use it.
Solution 2:
Use the following command to backup your home directory:
cd ~
tar -cvf /media/user/drive/home_backup.tar .
The first command ensures you are in your home directory. The second command backs up everything in this directory to an archive file called home_backup.tar
on external drive mounted under /media/user/drive
(you must adjust that part to reflect the actual path where your external drive is mounted).
On the new machine, conversely, use the following to restore your home directory:
cd ~
tar -xvf /media/user/drive/home_backup.tar
Try to avoid writing anyhting in the home directory while backup/restore is in progress, otherwise contents of the files that are written may become corrupted, either in the backup copy or in the restored file. (Be aware that some applications, like web browsers, are heavily writing to home directory, so it's best to avoid using any applications during backup/restore).
It is recommended to logout from GUI and login again after restore is completed (you are also restoring GNOME configuration files this way, some of them might get overwritten).
As @ubfan1 noted in the comment, ensure that your user ID and group ID on the new machine is the same as on the old one before attempting restore.