How would I use tar for full backup and restore with system on SSD and home on HDD?
The existing backup and restore answers don't seem to cover the case where root and home are on separate devices
It is adviced to make TWO backups. 1 for / and 1 for /home if they are on different partition. If you want one you will have to add a lot of exceptions to that one command. Example:
sudo su cd / tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system / tar -cvpzf backuphome.tar.gz --one-file-system /home/
will backup your root and exclude ALL mounted partitions, like /media (you do not want to backup external devices (you really do not)) and you absolutely do NOT want to backup something like /dev or /proc. And /home goes to another backup.
In above method the backup are stored in /. It will be bettter to store it on an external media; you can then put a directory in front of the backup.tar.gz and drop the
--exclude=... from the 1st command.
--excludewill prevent the actual backup to be backupped.
cvpzf: create, verbose, preserve permissions, compress, use a file.
--one-file-system - Do not include files on a different filesystem. If you want other filesystems, such as a /home partition, or external media mounted in /media backed up, you either need to back them up separately, or omit this flag. If you do omit this flag, you will need to add several more --exclude= arguments to avoid filesystems you do not want. These would be /proc, /sys, /mnt, /media, /run and /dev directories in root. /proc and /sys are virtual filesystems that provide windows into variables of the running kernel, so you do not want to try and backup or restore them. /dev is a tmpfs whose contents are created and deleted dynamically by udev, so you also do not want to backup or restore it. Likewise, /run is a tmpfs that holds variables about the running system that do not need backed up (Source).
So ... if you really still want a "one-liner" it could look like this:
cd / tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys /
(I hope I got all of what needs to be excluded)
Restoring would be
sudo su cd / tar xvzf backup.tar.gz
I did not use
sudo in front of the tar command since you will get error messages regarding permissions (because of files owned by root).