2

I have two partitions:

  • /dev/sda is mounted as /
  • /dev/sdb is mounted ias /stuff

I want to copy everything from / to /stuff/backup but I also want the symbolic links to update to point to/in /stuff/backup.

For example, if I have a symbolic link like so:

/path/to/some/link -> /path/to/the/real/file

Then after it is backed up it should look like this:

/stuff/backup/path/to/some/link -> /stuff/backup/path/to/the/real/file

I have googled a bit but can't seem to figure this out.

1 Answers1

3

From the discussion, IMO, tar is the best tool as it will preserve links. I also suggest doing this from a live CD. You would mount your ubuntu root partition and cd into it.

If you are backing up a database, use the database tools, ie mysqldump

From a running system (not live usb):

NOTE: Review these excludes before you run this command, see below for details.

Minimal excludes would be /proc /tmp /mnt /dev and /sys The others are optional but will significantly reduce the size of your backup

cd / # THIS CD IS IMPORTANT THE FOLLOWING LONG COMMAND IS RUN FROM /
tar -cvpzf backup.tar.gz \
--exclude=/backup.tar.gz \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/run \ 
--exclude=/media \ 
--exclude=/var/log \
--exclude=/var/cache/apt/archives \
--exclude=/usr/src/linux-headers* \ 
--exclude=/home/*/.gvfs \
--exclude=/home/*/.cache \ 
--exclude=/home/*/.local/share/Trash /

This will compress the archive, it is completely portable, and is located at /backup.tar.gz

What the options mean: from https://help.ubuntu.com/community/BackupYourSystem/TAR

tar - is the command that creates the archive. It is modified by each letter immediately following, each is explained bellow.

c - create a new backup archive.

v - verbose mode, tar will print what it's doing to the screen.

p - preserves the permissions of the files put in the archive for restoration later.

z - compress the backup file with 'gzip' to make it smaller.

f - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.

The \ just continue the command on the next line and I added them for clarity.

The --exclude should be self evident, but it excludes those directories.

You can use the --one-file-system option rather then all the excludes for /proc, /sys, /mnt, /media, /run and /dev , however, if you have a separate /boot or /home (or other partition) you would need to add it into the archive.

You can exclude directories you know you do not need, ie have no edits. /usr/share or similar.

To view the contents see How can I view the contents of tar.gz file without extracting from the command-line?

You can see the file contents with vim / gvim and list differences with zdiff

EDIT: From the comments "It bombs half way through showing: /lib/plymouth/themes/ /lib/plymouth/themes/ubuntu-text/ tar: /: file changed as we read it after 10 minutes on a mini-PCIe SSD (Sata II channel). This will take some time to fine tune"

This happens because the file system is in use so if there are changes written to disk during the tar you will get these sorts of messages. This sort of problem can be avoided by excluding as much as possible in the tar archive and/or running tar from a live CD/USB

Also, from the comments, other candidates for exclusion are :

~/.cache # These files are completely unnecessary and in fact you can at any time recover disk space by deleting this directory.

/usr/src/linux-headers* # Again , large amount of data you do not need.

~/.local/share/Trash # Review and delete trash or exclude this directory

/media # Will have for example Windows partions

/var/run/user/$USER/... which is a symbolic link to /run so I --exclude=/run as well. #This will have removable devices such as flash driver and android devices so probably can be excluded.

Panther
  • 104,528