-[[.:start]]
====== Laptop Backup via rsync ======
** A simple way to keep a backup of my laptop Home directory **
===== Backup hosts =====
**where to put the backups for safe keeping **
* A NAS box on my home LAN : ''nas1''
* An old Lenovo Laptop acting as a LAN file server : ''laptop''
* My cloud VPS server : ''g4slv.info''
===== Rsync Script =====
To automate the backup to any of the three backup hosts above I've got a script, obviously.
The script checks which hosts are currently online and reachable and backs up the same data to each of them. This check means any of the hosts can be turned off but the script won't simply hang waiting for connection timeout before trying the next hosts.
To reduce the traffic, and to limit backing up needless data (i.e. don't just backup the whole of $HOME) I have an ''exclude'' file that lists files and directories that should be ignored.
The backups are saved in a remote Directory called "devuan" - the laptop being backed up is running Devuan linux and has the hostname ''devuan''
I also backup a mirror of the wiki to the local NAS and Laptop hosts (as long as I remember to pull a backup/mirror down from the wiki server first). There's no point in backing //this// up to the remote VPS - since that's the machine where the wiki lives in the first place!
==== Exclude ====
/fetch
/fetch.png
/.fehbg
.lesshst
.viminfo
*mutt*
aur/
muttheadercache
muttmessagecache/
*.img
*.iso
.cache/
.claws-mail/
.cups/
.dbus/
.fonts/
.mozilla/
.librewolf/
Kate/
.config/chromium/*
.config/pulse/*
.config/xfce4*
.config/libreoffice
.local/bin/*
.local/share/*
.zoom/*
Pictures/*
Downloads/*
Nextcloud/
yadd_full*
eSIM*
bin/dokuwiki/*
==== Rsync Script ====
#!/bin/bash
#
# The NAS1 destination is a share called Backups
# which is accessed via "daemon rsync" at nas1::Backups
# rather than a directory in /home/g4slv
# this allows passwordless rsync. Necessary since the ssh
# server @ nas1 is too old to accept identity keys from
# modern ssh clients - so normal rsync-over-ssh would require
# a password.
#
# Using a "module" overcomes this, and allows for automatic
# backups.
#
EXCLUDEFROM=~/exclude
SOURCE=/home/g4slv/
DEST=devuan
WIKI=wiki
#CLOUD=217.154.53.244
CLOUD=g4slv.info
# Test if the destinations are reachable
NAS=` ping -c 1 -w 1 192.168.21.5 | grep received | awk '{print $4}'`
LAPTOP=` ping -c 1 -w 1 192.168.21.101 | grep received | awk '{print $4}'`
INFO=` ping -c 1 -w 1 $CLOUD | grep received | awk '{print $4}'`
if [ $NAS == 1 ]
then
rsync -av --delete /var/www/html/ 192.168.21.5::Backups/$WIKI
rsync -av --exclude-from=$EXCLUDEFROM $SOURCE 192.168.21.5::Backups/$DEST
else
echo "NAS1 not found"
fi
if [ $LAPTOP == 1 ]
then
rsync -av --delete /var/www/html/ 192.168.21.101:backups/$WIKI
rsync -av --exclude-from=$EXCLUDEFROM $SOURCE 192.168.21.101:backups/$DEST
else
echo "Laptop not found"
fi
if [ $INFO == 1 ]
then
rsync -av -e 'ssh -p xxxx' --exclude-from=$EXCLUDEFROM $SOURCE $CLOUD:backups/$DEST
else
echo "Server INFO not found"
fi
==== Dokuwiki Mirror/Backup ====
I have a script to pull a copy of the dokuwiki files from the VPS and put them in ''/var/www/html/*'' on my laptop. The laptop runs ''apache2'' and can server the wiki itself. This mirror can be backed up through the above script to the other backup hosts ''nas1'' and ''laptop''
#!/bin/bash
rsync -av -e "ssh -p xxxx" --progress xxxx@g4slv.info:/var/www/html/dokuwiki/ dokuwiki/
sudo rsync -av dokuwiki/ /var/www/html/dokuwiki/
sudo chown -R www-data:www-data /var/www/html/dokuwiki
--- //John Pumford-Green 29/01/26 13:48 GMT//
===== Further Information =====
{{tag>computer backup}}