Okay i have found a good solution using zenity. Below i attached some todos for users who are not familiar with all those admin stuff ;)...
What the script is doing:
- Check if remote host is reachable
- Ask if you want to perform the backup in the GUI (with Zenity)
- Using rsync with ssh to backup to remote machine
- Backup list of installed packages
- Script is made to perform full system backup of / and all its subdirectories
- Executed autmatically once a day using anacron/cron
Here is the script:
#!/bin/bash
#preperations...
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:
export DISPLAY=:0.0
export XAUTHORITY=/home/$USER/.Xauthority
#check if host is reachable
ping -c1 -W1 -q $iptoremotehost &>/dev/null #put in the host adress here
status=$( echo $? )
if [[ $status == 0 ]] ; then
#ask if backup should be performed if the remote host is reachable
if
! zenity --question --text "Grab a coffee and perform backup?"; then exit;
fi
#backup Packages
dpkg --get-selections > /pathtoyour/Packages.txt #file needs to be created first
#backup whole machine with some excluded folders (not to produce infinite loops). Take care of -i param in rsync because by default it is not using the right private key for ssh connection (in my case this was a problem).
rsync --rsync-path="sudo rsync" --delete --exclude-from='/pathtoyour/rsync_exclude.txt' -aAXPv -e 'ssh -i /pathtoyour/privatekey' $yoursourcedirectory rsyncuser@$iptoremotehost:$yourdestinationdirectory |
awk -f /pathtoyour/rsync.awk | #this file must be created first!
zenity --progress --title "Full System Backup" \
--text="In process..." --percentage=0 --auto-kill
else
exit
fi
TODO to get it working:
- Create files rsync.awk, rsync_exclude-txt (content see below)
- Put backup script in /etc/cron.daily and make it executable
- Setup a ssh connection using a public key, which is replacing the
password when sshing to your host. (See:
https://www.cyberciti.biz/faq/how-to-set-up-ssh-keys-on-linux-unix/)
Create a $rsyncuser on the remote host and create a group where you
add the rsyncuser to and also the normal user. Change the permission
so that the new group can access read and write the $destinationpath
of your backup.Don't forget to install the ssh key to the new user,
so that no password is required when sshing!
As to preserve the right permissions on the backuped files and
directories add you have to allow the $rsyncuser to run sudo rsync
(on the remote machine) without password prombt:sudo visudo
and
add rsyncuser ALL = NOPASSWD: /usr/bin/rsync
Grab a beer and perform backup!
rsync.awk:
{
if (index($0, "to-chk=") > 0)
{
split($0, pieces, "to-chk=")
split(pieces[2], term, ")");
split(term[1], division, "/");
print (1-(division[1]/division[2]))*100"%"
}
else
{
print "#"$0;
}
fflush();
}
rsync_exclude.txt:
dev*
proc*
sys*
tmp*
run*
mnt*
lost+found*
home/$USER/.ssh/*
Don't forget to add the directory where the private key of your ssh connection is lying. Otherwise it would be a security issue!
Feedback appreciated!