Backing-up the Ubuntu system

I know this thread is a little old now, but I wanted to share the process I use to backup my system, and photos, just in case any one else maybe looking for this.

There really is no reason to use external tools, as some of the best backup tools are all ready included with Linux, and all it take is creating a small script file.

This is my systembackup.sh script file, residing in my root scripts folder.

#!/usr/bin/env bash
#
# Backup system
# Preserve permissions and ACL's
# Run the task on processor nodes 10 and 11

taskset -c 10,11 \
    rsync -aAX --delete \
    --exclude=/dev/* \
    --exclude=/proc/* \
    --exclude=/sys/* \
    --exclude=/tmp/* \
    --exclude=/run/* \
    --exclude=/mnt/* \
    --exclude=/media/* \
    --exclude="swapfile" \
    --exclude="lost+found" \
    --exclude=".cache" \
    --exclude="Downloads" \
    --exclude=".VirtualBoxVMs" \
    --exclude=".ecryptfs" \
    / \
    /mnt/BACKUP_DRIVE/System \
    &

Lets break this down a little, first the rsync backup part of the script:

  • -a
    This option is a combination flag. It stands for “archive” and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions.
  • -A, --acls
    Preserve ACLs (implies --perms)
  • -X, --xattrs
    Preserve extended attributes
  • --delete
    Delete extraneous files from destination dirs (be careful with this) if a file in the destination is not in the source it will be deleted. So make sure that your source and destination are correct.
  • --exclude=PATTERN
    Exclude files matching PATTERN (There are a whole bunch of files that you don’t need to backup, this excludes them.
  • /
    The root directory I want to backup.
  • /mnt/BACKUP_DRIVE/SYSTEM
    The destination drive.
  • &
    Run the process in the background

So that’s the backup part of the script, after the initial backup it only copy across changes in the root system. Now an issue I found was that when I ran this backup my system could slowdown, even hang, as the process was running. I have a 12 core CPU, and the load was shared across all cores, meaning other running processes would suffer.

  • taskset -c 10,11
    What this does is assign processor cores 10 and 11 to the task, allowing my machine to keeps running smoothly while the backup is running. I especially found this useful when I had to transfer 2Tb of images to a new drive.

My backup script can be set as a cron job, or ran manually as I desire.
In case of system failure, i just need to boot with a live USB, and copy the files back using the same process.

I have a separate script to backup my photos directory, it is pretty much the same:

#!/usr/bin/env bash
#
# Backup photos preserving permissions
# Run the task on processor nodes 8 and 9

taskset -c 8,9 \
    rsync -ap --delete \
    /mnt/USER_DATA/Photos/ \
    /mnt/BACKUP_DRIVE/Photos
2 Likes