YadAndYin and Anacronism

Welcome to Anacronism(sp) my script for backing up your personal home directory tested under Linux Mint 64 bit Cinnamon on 11/01/16 but should work ok as it has 32 bit directory structure too but i haven't tried it on 32 bit yet. The script assumes some basic knowledge of terminal commands such as ls and a lightweight script editor like Pluma or Gedit etc. Or perhaps you want the whole system approach using Zenzilla.

*Note disclaimer you run it at your own risk and no responsibility is taken by me. ( although all care taken to write it ) This is a screenshot of the main window that comes up every time it is run. ( Anacron runs it once a day and th script decides if it the right day Tuesday )

 

Just a script for Yad ( program to output stuff to the screen in linux ) it just outputs that its going to do a backup or not using rsync depending on if it has run today anacron scripts only run once a day in this setup. 


first install Yad using apt yad install or apt install zenity
 and you can download the scripts below if you don't want too much copy and paste


pluma /etc/anacrontab  ( this will launch a small editor called pluma and edit a file in the /etc directory )
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries

1 5 cron.daily run-parts --report /etc/cron.daily
1   1  mycron.daily  /root/anacronism.sh /etc/cron.daily
7 10 cron.weekly run-parts --report /etc/cron.weekly
@monthly 15 cron.monthly run-parts --report /etc/cron.monthly

now save the above or you can test it with anacron -d

edit a program in /root called anacronism.sh using your favourite editor (i used pluma)
then put these following lines in it ( example1 )
#!/bin/bash
# script to sync specified folder to another destination via rsync.
# Put this to ~/.gnome2/nautilus-scripts
# Written by Stephen P some parts based on script  by Anton Keks on Github

paths_file=$(readlink -f $0).paths
slash="/"
date_file=$(pwd)$slash.lastrun


#pw_dir= `pwd`
locations=`cat $paths_file`
sources=`cat $paths_file | awk -F'|' '{print $1}'`

#note this last part is so the script doesn't need to be run more than once a day needs fixing tip try putting the string
#in the dialog then run via crontab then you see it is not right ... didn't need to fix used anacron to launch it :)

datestr=`more  $date_file`

#if [ $datestr = `date +"%D"` ]; then
#exit;
#fi


echo "last date of back up was completed on the "$datestr
#export authorisation so that you can display on this monitor
export XAUTHORITY=/home/youruser888/.Xauthority
#DISPLAY=:0.0 zenity --question --text "Backup time .. is HDD connected?"

#execute this script on the 2nd day of the week or in other words every Tuesday in a 7 day period.
#the u switch on the day command gives this ( for example the number 2 for Tuesday )
datestr='2'
echo 'It is the '`date +%u`' day of the week.'
if [ ! $datestr = `date +%u` ]; then
echo 'This is not a back up day therefore exiting script here this will not be shown to the user only in terminal mode to change the day change the datestr variable on the previous line.'
exit;
fi

#source=`readlink -f "$source"`
#source=${source%/}

if  [ -f "$source" ]; then


DISPLAY=:0.0  zenity --error --text="$source is not a directory it is a file or invalid directory exiting script."; exit 2
fi

if [ $2 ]; then
  # TODO: support multiple sources
 DISPLAY=:0.0 zenity --warning --text="Only one directory can be synced, using $source"
fi



DISPLAY=:0.0 zenity --warning --text="Time for backing up your system .
 Please minimise any user tasks for a minute or so while this process occurs
 to avoid errors and a slow down of the archive activity you will be notified of
 completion by a window like this one, thanks for your patience and reading 
this huge dialog window, don't forget to connect any back up external drives 
to the USB port if you have set up those as your preferred storage device. 
The home (source) directory is /home/youruser888/Downloads,Pictures
,Documents,Desktop,Music etc to the destination directories
 /mnt/D210AE5D10AE47F5 and /media/youruser888/D210AE5D10AE47F5
 you can edit these paths in the Bash script file that this was run from. 
Last back up was performed on the date "`date +%D`". Script programming
 help follows "$date_file"present working directory is "`pwd`


# chage the yourUser888 to your user name and D210AE5D10AE47F5 to your backup devices string
# check your devices with ls /media or ls /mnt like picture above

rsync -vrlptD "/home/yourUser777/Downloads" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Documents" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Desktop" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Keys" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Pictures" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Public" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Music" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Movies" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Templates" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Videos" "/media/yourUser777/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"

# system  mounts them on /mnt instead of /media if using cinnamon

rsync -vrlptD "/home/yourUser777/Backupscripts" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/BackupISOs" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Dictionaries" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Documents" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Desktop" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Downloads" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Keys" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Pictures" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Public" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Music" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Movies" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Templates" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
rsync -vrlptD "/home/yourUser777/Videos" "/mnt/289ddbde-40e7-4aa6-8a16-c9cfc315bfae/yourUser777"
#date +"%D" > .lastrun
date  >> slastrun.txt
DISPLAY=:0.0 zenity --warning --text="Completed back up, you can go back to watching TV,internet etc now."

# note: delete-delay below means that any files will be deleted only as a last step
#rsync $rsync_opts --delete-delay --progress "$source" "$dest" | awk "$rsync_progress_awk" | zenity --progress --#width=350 --title="Synchronizing $source" || exit 4



# example rsync line to back up a windows NTFS filesystem to a Linux one ( needed to be mounted beforehand )

sudo rsync -vrlptD /media/ntfs/Documents\ and\ SettingsWINDOWSUSERNAME/My\ Documents/G-Z/ /home/LINUXUSERNAME/Backups/



Final notes
added report.sh its a demo of reminding you every Wednesday to do a report when you start your computer


ċ
anacronism.sh
(6k)
Stephen P,
Dec 9, 2016, 3:38 PM
ċ
anacronism2.sh
(7k)
Stephen P,
Jan 27, 2017, 11:23 PM
ċ
anacrontab
(1k)
Stephen P,
Oct 31, 2016, 5:25 PM
ċ
report.sh
(1k)
Stephen P,
Oct 31, 2016, 2:37 PM
ċ
systemDhacks2
(0k)
Stephen P,
Dec 9, 2016, 3:30 PM
Comments