Difference between revisions of "Laptop Backup"
From
Line 12: | Line 12: | ||
* Backup to a NFS share at 192.168.12.75 | * Backup to a NFS share at 192.168.12.75 | ||
* The NFS share is mounted at /mnt/nas/michiel/ | * The NFS share is mounted at /mnt/nas/michiel/ | ||
− | * | + | * First backup: Laptop -> Nas (Laptop runs the backup script) |
+ | * Second backup: Nas -> stack (External server runs the backup script) | ||
− | == Before running... == | + | == 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/ | ||
+ | * First backup: Laptop -> Nas | ||
+ | * Laptop runs the backup script | ||
+ | |||
+ | === Before running... === | ||
* Make sure the directory "backup" exist on the NFS share. | * Make sure the directory "backup" exist on the NFS share. | ||
− | * Make sure screen is installed | + | * Make sure screen is installed on your laptop. |
Run the following command at the root of the NFS share. | Run the following command at the root of the NFS share. | ||
<syntaxhighlight lang="Bash"> | <syntaxhighlight lang="Bash"> | ||
− | printf "Welcome01" | + | printf "Welcome01" > .password |
</syntaxhighlight> | </syntaxhighlight> | ||
− | == Backup == | + | === Backup Script === |
− | + | /opt/laptopbackup ("chmod +x /opt/laptopbackup" after creating file) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<syntaxhighlight lang="Bash"> | <syntaxhighlight lang="Bash"> | ||
#!/bin/bash | #!/bin/bash | ||
Line 82: | Line 50: | ||
: 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 [ | + | if [ "$(cat "/mnt/nas/michiel/.password" | shasum -a 512)" = "eb6689158408aee35adb6b7ed148d5458073554439a184ad9b787d834c7eaa1df7103ddda2b31ff608de184d7d4f4d08f82bc86884a6ed0fa93e30d31e6bf055 -" ] ; then |
echo "password accepted" | echo "password accepted" | ||
− | |||
else | else | ||
echo "Backup script: Wrong password at NFS share" | echo "Backup script: Wrong password at NFS share" | ||
Line 93: | Line 60: | ||
: Rsync the whole system except some directories. | : Rsync the whole system except some directories. | ||
echo "Backup script: Rsync is running" | 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" | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | To except some directories, replace rsync with the following command | ||
+ | <syntaxhighlight lang="Bash"> | ||
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 | 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 | ||
+ | </syntaxhighlight> | ||
− | + | ===Run the script=== | |
+ | To run the script, use the following command. | ||
+ | <syntaxhighlight lang="Bash"> | ||
+ | sudo bash /opt/laptopbackup | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | 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. | ||
== Resources == | == Resources == |
Revision as of 19:41, 20 December 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 |
Contents
Information
- Laptop is Debian based.
- Backup to a NFS share at 192.168.12.75
- The NFS share is mounted at /mnt/nas/michiel/
- 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/
- First backup: Laptop -> Nas
- 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.