Difference between revisions of "Laptop Backup"
From
(→Backup) |
|||
Line 3: | Line 3: | ||
|Owner=fridgefire | |Owner=fridgefire | ||
|Skillz=Bash magic | |Skillz=Bash magic | ||
− | |Status=In progress | + | |Status=In progress, not working yet |
|Summary=A way to backup a laptop | |Summary=A way to backup a laptop | ||
}} | }} | ||
Line 71: | Line 71: | ||
: check if we can ping 192.168.12.75 | : check if we can ping 192.168.12.75 | ||
ping -q -c5 192.168.12.75 > /dev/null | ping -q -c5 192.168.12.75 > /dev/null | ||
− | if [ $? -eq 0 ] | + | if [ $? -eq 0 ] ; then |
echo "ping is succeeded" | echo "ping is succeeded" | ||
else | else | ||
Line 77: | Line 77: | ||
exit 0 | exit 0 | ||
fi | fi | ||
− | + | ||
: Mount NFS share at /mnt/nas/michiel | : Mount NFS share at /mnt/nas/michiel | ||
mount 192.168.12.75:/shares/michiel /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. | : 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 | if [ "$(printf "Welcome01" | shasum -a 512)" = "$(cat "/mnt/nas/michiel/.password")" ] ; then | ||
Line 86: | Line 86: | ||
exit | exit | ||
else | else | ||
− | echo | + | echo "Backup script: Wrong password at NFS share" |
− | + | ||
exit 0 | exit 0 | ||
fi | fi | ||
− | + | ||
− | + | ||
: Rsync the whole system except some directories. | : Rsync the whole system except some directories. | ||
− | echo | + | 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$ | |
− | 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 | + | echo "Backup script: Yeey, backup is finished" |
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 20:01, 1 June 2016
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/sh 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$ echo "Backup script: Yeey, backup is finished"