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:
#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
! zenity --question --text "Grab a coffee and perform backup?"; then exit;
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
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:
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
(on the remote machine) without password prombt:
sudo visudo and
rsyncuser ALL = NOPASSWD: /usr/bin/rsync
Grab a beer and perform backup!
if (index($0, "to-chk=") > 0)
split($0, pieces, "to-chk=")
split(pieces, term, ")");
split(term, division, "/");
Don't forget to add the directory where the private key of your ssh connection is lying. Otherwise it would be a security issue!