Laptop Backup
From
Project: Laptop Backup | |
---|---|
360x360px | |
Name | Laptop Backup |
Initiator | fridgefire |
Status | Working |
Skills | Bash magic |
Summary | A way to backup a laptop |
Contents
Disclaimer
Do not blame me if something breaks.
Information
- First backup: Laptop -> Nas (Laptop runs the backup script)
- Second backup: Nas -> stack (External server runs the backup script)
Laptop to Nas backup
Information
- Laptop is Debian based.
- Backup to a NFS share at 192.168.12.75
- The NFS share is mounted at /mnt/nas/michiel/
- Laptop runs the backup script
Before running...
- Make sure the directory "backup" exist on the NFS share.
- Make sure screen is installed on your laptop.
Run the following command at the root of the NFS share.
printf "Welcome01" > .password
Backup Script
/opt/laptopbackup ("chmod +x /opt/laptopbackup" 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 [ "$(cat "/mnt/nas/michiel/.password" | shasum -a 512)" = "eb6689158408aee35adb6b7ed148d5458073554439a184ad9b787d834c7eaa1df7103ddda2b31ff608de184d7d4f4d08f82bc86884a6ed0fa93e30d31e6bf055 -" ] ; then echo "password accepted" 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 /home/michiel /mnt/nas/michiel/backup/laptop/home/michiel echo "Backup script: Yeey, backup is finished"
To except some directories, replace rsync with the following command
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
Run the script
To run the script, use the following command.
sudo bash /opt/laptopbackup
Use sudo to make sure the permissions don't change. Also use bash instead op "./" or "sh" because otherwise you can get some bugs with the exclude parameters.
Nas to TransIP Stack backup
Information
- Server is Debian based.
- Backup to a webdav share at /mnt/stack/nas/michiel/backup/
- The NFS share is mounted at /mnt/nas/michiel/
- Server runs the backup script
- Server is a external server. Do not confuse my server and my nas. They are different :)
Before running...
- Make sure the directory "backup" exist on the NFS share.
- Make sure the TransIP Stack server is mounted at /mnt/stack
- Make sure the directory "/mnt/stack/nas/michiel/backup/" exist on the webdav share.
- Make sure screen is installed on your laptop.
Run the following command at the root of the webdav share.
printf "Welcome01" > .password
Backup Script
/opt/serverbackup ("chmod +x /opt/serverbackup" after creating file)
#!/bin/bash while true do 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 [ "$(cat "/mnt/nas/michiel/.password" | shasum -a 512)" = "eb6689158408aee35adb6b7ed148d5458073554439a184ad9b787d834c7eaa1df7103ddda2b31ff608de184d7d4f4d08f82bc86884a6ed0fa93e30d31e6bf055 -" ] ; then echo "password accepted" else echo "Backup script: Wrong password at NFS share" exit 0 fi : Mount webdav share at /mnt/stack mount /mnt/stack : Check password in /mnt/stack/.password to make sure you are connected to the right NFS share. if [ "$(cat "/mnt/stack/.password" | shasum -a 512)" = "eb6689158408aee35adb6b7ed148d5458073554439a184ad9b787d834c7eaa1df7103ddda2b31ff608de184d7d4f4d08f82bc86884a6ed0fa93e30d31e6bf055 -" ] ; then echo "password accepted" else echo "Backup script: Wrong password at Stack share" exit 0 fi : Rsync the whole system except some directories. echo "Backup script: Rsync is running" rsync -aAXH --delete --info=progress2 /mnt/nas/michiel/backup/ /mnt/stack/nas/michiel/backup/ echo "Backup script: Yeey, backup is finished" done
Run the script
To run the script, use the following command.
sudo bash /opt/serverbackup
Use sudo to make sure the permissions don't change. Also use bash instead op "./" or "sh" because otherwise you can get some bugs with the exclude parameters.