This wiki has been archived and made read-only.
For up-to-date information about TkkrLab and it's projects please visit our main website at tkkrlab.nl.

Laptop Backup

From

Revision as of 20:38, 1 June 2016 by Michiel brink (Talk | contribs)

Jump to: navigation, search
Project: Laptop Backup
360x360px
Name Laptop Backup
Initiator fridgefire
Status In progress, not working yet
Skills Bash magic
Summary A way to backup a laptop


Information

  • Laptop is Debian based.
  • Backup to a NFS share at 192.168.12.75
  • The NFS share is mounted at /mnt/nas/michiel/
  • Backup only when eth0 or eth1 is connected and the laptop can ping to the NFS share.

Before running...

  • Make sure the directory "backup" exist on the NFS share.
  • Make sure screen is installed

Run the following command at the root of the NFS share.

printf "Welcome01" | shasum -a 512 > .password

Backup

/etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet dhcp
post-up /etc/network/backup
 
auto eth1
iface eth1 inet dhcp
post-up /etc/network/backup

/etc/network/backup (chmod +x /etc/network/backup after creating file)

#!/bin/sh
: Check if script is not started before last boot.
FLAGFILE=/var/run/backup-is-started
 
case "$IFACE" in
    lo)
        # The loopback interface does not count.
        # only run when some other interface comes up
        exit 0
        ;;
    *)
        ;;
esac
 
if [ -e $FLAGFILE ]; then
    exit 0
else
    touch $FLAGFILE
fi
 
: Start backup
screen -S backup '/etc/network/backupscreen'

/etc/network/backupscreen (chmod +x /etc/network/backupscreen after creating file)

#!/bin/bash
echo "start backup"
: check if we can ping 192.168.12.75
ping -q -c5 192.168.12.75 > /dev/null
if [ $? -eq 0 ] ; then
    echo "ping is succeeded"
else
    echo "Can not ping to server"
    exit 0
fi
 
: Mount NFS share at /mnt/nas/michiel
mount 192.168.12.75:/shares/michiel /mnt/nas/michiel
 
: Check password in /mnt/nas/michiel/.password to make sure you are connected to the right NFS share.
if [ "$(printf "Welcome01" | shasum -a 512)" = "$(cat "/mnt/nas/michiel/.password")" ] ; then
  echo "password accepted"
  exit
else
  echo "Backup script: Wrong password at NFS share"
  exit 0
fi
 
 
: Rsync the whole system except some directories.
echo "Backup script: Rsync is running"
rsync -aAXH --delete --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*/.thumbnails/*","/home/*/.cache/*","/home/*/.local/share/Trash/*","/home/*/.gvfs","/home/*/Downloads"} / /mnt/nas/michiel/backup
 
echo "Backup script: Yeey, backup is finished"

Resources