what?

a simple file wise rsync based backup of your system (currently without boot partition or boot manager) that:

  • does exclude mountpoints on debian and centos – thus really only backups your internal root partition /dev/sda (probably)
  • automatically creates subdirectory in the structure hostname/year-month-day
  • test if your backup destination exists (cancels backup if not)

NOTE: It would be wise to powerdown the system – boot from IDEAL-Linux-Stick and do a dd wise backup of /dev/sda as well, because this will backup every bit on your root partition including boot partition, boot manager etc. etc.

but because people tend to be lazy and machines hate offline backups, at least do the file wise manual started backups to your external drive that you then (of course) carry home and not leave in the office (where it might get stolen) – so you can sleep well at night.

usage

if it not allready has – label your external drive „BACKUP“:

tune2fs -L "BACKUP1" /dev/sdc1; # label

unplug, plugin… it should be automatically mounted as BACKUP1 under /run/media (CentOS/RedHat) or /media/ (Debian/Ubuntu)

find out where your external backup drive was mounted:

mount|grep BACKUP1
/dev/sdc1 on /run/media/StandardUser/BACKUP1 type ext3 (rw,nosuid,nodev,relatime,seclabel,data=ordered,uhelper=udisks2)

create new script in your script collection directory:

vim /scripts/backup.sh

fill it with:

#!/bin/bash
echo "
   _____ _____   _____ ____   _____ 
  / ____|  __ \ / ____|  _ \ / ____|
 | (___ | |__) | (___ | |_) | (___  
  \___ \|  _  / \___ \|  _ / \___ \ 
  ____) | | \ \ ____) | |_) |____) |
 |_____/|_|  \_\_____/|____/|_____/ 

SimpleRsyncSystemBackupScript v1.0";

# this is where my external drive is mounted without trailing /
DESTstatic=/run/media/StandardUser/BACKUP1 <- MODIFY THIS LINE!

if [ -d "$DESTstatic" ]; then

DEST=$DESTstatic/$(hostname)/$(date +"%Y-%m-%d")
cd $DESTstatic;
mkdir $(hostname);
cd $(hostname);
mkdir $(date +"%Y-%m-%d");
echo ".............. backup destination:" $DEST;
rsync --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs} -aAXv --update / $DEST;
chown -R StandardUser:StandardUser $DEST;

else

echo ".............. backup destination:" $DESTstatic;
echo "!DOES NOT EXIST! CAN NOT BACKUP! PLEASE MODIFY THIS SCRIPT AND FIX BACKUP DESTINATION PATH DESTstatic!";

fi

make it runnable

chmod +x /scripts/backup.sh

run it as root:

su; # become root
# or
sudo /scripts/backup.sh

you either get an error that your backup directory does not exist… or it will start the backup.

regular filesystem checks:

are also important to keep your backup files in order.

tune2fs -C 1 -c 10 /dev/sdc1; # check filesystem every 10 boots/mounts

you can check that a filesystem check was performed with:

tune2fs -l /dev/sdc1 | egrep -i "mount count|Check interval|Last|Next"
Last mounted on: /run/media/canoodle/BACKUP1
Last mount time: Sat Jan 20 09:43:02 2018
Last write time: Sat Jan 20 09:43:02 2018
Mount count: 2
Maximum mount count: 10
Last checked: Sun Dec 3 11:23:00 2017
Check interval: 0 (<none>)

or have the filesystem checked straight after the backup:

ll /dev/disk/by-uuid/ | grep sdc1
lrwxrwxrwx. 1 root root  10 Jan 20 09:43 43c5d78f-70d0-45df-8cf7-ce17bf59cac5 -> ../../sdc1

# then include those two lines before "else"
umount /dev/disk/by-uuid/43c5d78f-70d0-45df-8cf7-ce17bf59cac5;
fsck -y -v -f /dev/disk/by-uuid/43c5d78f-70d0-45df-8cf7-ce17bf59cac5;
admin