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.
/
directory. – IMTheNachoMan Jul 16 '17 at 14:06/
folder. – IMTheNachoMan Jul 16 '17 at 14:09/etc
. So I thought if I could take a copy fo the entire/
to/mnt/data/backup
then I could look at the files I need when I need it. – IMTheNachoMan Jul 16 '17 at 16:19/etc/fastab
for example, I save a copy of my new file in/root/etc/fstab
. Then when I backup I only need to back up /home /root and any server data such as /var/www/html or mysql database. – Panther Jul 16 '17 at 16:30cd / tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys /
. This excludes directories you do not want to copy, preserves links, and compresses the archive. – Panther Jul 16 '17 at 16:31/var/log
and/var/cache/apt/archives
your downloaded packages or just tar /etc or wherever you edited files + /home + /root + /var/www/html . – Panther Jul 16 '17 at 16:34