Author Topic: Simple Rsync of Dirs  (Read 1135 times)

statmonkey

  • Posts: 330
    • View Profile
Simple Rsync of Dirs
« on: September 26, 2013, 07:06:42 PM »
I'll start with one I use a great deal.  It is part of a more complex script that I will post later that does a routine of things but one of the great things about these is you can really cut and paste them back and forth the codlets once you have a few are easy to build off (actually yad more so) but that is again another subject.

So this little guy sits in my sbin and is a menu choice and has a key combo as well and when I want to (for example) start deleting half my root drive.  I just pop this open, back the bad boy up and then play havoc to my hearts content.

Code: [Select]
#!/bin/bash
#/==========================================================================
# TITLE: Backup
# AUTHOR:Statmonkey
#
# USAGE: Rsync and directory anywhere or the media directories
# DESCRIPTION: Graphical backup script using zenity

# ARCHIVE DATA USING Rsync and Zenity
# Allows you to select your source and destination
# Allows you to select your exclude filelist from a preset set of lists (this is in full script)
# Uses logger to log to syslog and logs everything in detail to a sourcelog which is rotated every run (full script)
# Allows auto setting rsync options, deletes files not on source and asks for deletion confirmation (full script)
# Presents use with a summary of a dry run (dry run does not include excludes)   
#
# Requires: exclude file in source, zenity, rsync
#
#         
# DATE: LAST UPDATED 9/25/2013 THIS IS ABBREV. FOR QUICK BACKUP USAGE
#==========================================================================
#
#
# SOURCE and DEST variables are defined thru GUI
###############################################
# Define Log Variables:
###############################################
# write to syslog the overall log that records what? FIXME
SYSLOG="/var/log/syslog"
echo $SYSLOG

###############################################
# Define DATE
###############################################

TODAY=`date +%m_%d_%y`

# Refer to closing lines of script for output
echo "The script Backup is starting"

#####################################
# Allow for a simple rsync
#####################################
zenity --question --title="Simple Backup" --text="Did You want a simple backup? Else, Quit!" --ok-label="Yes"
if [[ $? == 0 ]] ; then
SOURCE=`zenity --file-selection --directory --title "Select directory for source"`
echo $SOURCE
DEST=`zenity --file-selection --directory --title "Select directory for destination"`
echo $DEST
rsync -av "$SOURCE" "$DEST"
logger "Backed up $SOURCE $DEST"
echo "did backup $SOURCE $DEST $TODAY" >> $SYSLOG
exit 4
fi
# This ends the simple sync section. 
exit 4
##########

There are a few inefficiencies here and imperfections there but it meets my needs and the fun is it does what I want and I did it.  That is as much a part of the experience for me as anything else.  If anyone has a script they love, I would love to see it.  Even if not perfect the journey is the goal in this case.