1

I have searched around but could not find a tutorial on how to add a progressbar or progress notification within KDE plasma. My aim is pretty simple: make a rsync backup script which is fired up by cron/anacron and placed in /sbin to be run as root and to backup my whole system (via ssh). Furthermore to show a progressbar in KDE plasma's notification area when the script starts is executed by cron/anacron. So far a have used the script from this ubuntuusers.de: https://wiki.ubuntuusers.de/Skripte/Backup_mit_RSYNC/

Thanks!

2
  • In response to your earlier question, Zenity was suggested. You could also look at Yad which is a fork of Zenity and has more features.
    – DK Bose
    Commented Nov 13, 2019 at 0:00
  • 1
    Yes but I had problems piping in the values from the command to zenity....I managed it with awk see davidverhasselt.com/zenity-rsync-and-awk but the problem still is that rsync is doing its job but the zenity window is not poping up (problem seems to be maybe that I am logged in KDE as user and not as root who is executing the script due to /sbin where the script is placed....any hints?
    – user634093
    Commented Nov 14, 2019 at 17:10

1 Answer 1

0

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:

  1. Create files rsync.awk, rsync_exclude-txt (content see below)
  2. Put backup script in /etc/cron.daily and make it executable
  3. 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/)
  4. 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!

  5. 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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .