summaryrefslogtreecommitdiff
path: root/rsyncshot
diff options
context:
space:
mode:
authorCraig Jennings <cjennings@citizen.lan>2021-04-04 15:12:34 -0500
committerCraig Jennings <cjennings@citizen.lan>2021-04-04 15:12:34 -0500
commit8143a7e6890b3127968a45b839bcd1bc1b33cc8a (patch)
tree8a03f5b5d55d84915740f3d2fec539ec02bc9671 /rsyncshot
parentcb1c45a7cc4626ff88b84075916e3e2ba878aaff (diff)
Made rsyncshot "literate" (rsyncshot.org).
Comments coming back in once I get org properties working as expected.
Diffstat (limited to 'rsyncshot')
-rw-r--r--[-rwxr-xr-x]rsyncshot35
1 files changed, 3 insertions, 32 deletions
diff --git a/rsyncshot b/rsyncshot
index 7a4d0b5..d12827e 100755..100644
--- a/rsyncshot
+++ b/rsyncshot
@@ -1,8 +1,4 @@
#!/bin/bash
-#
-# rsyncshot
-# Craig Jennings craigmartinjennings@gmail.com
-# Inspired by Mike Rubel: http://www.mikerubel.org/computers/rsync_snapshots/
# uncomment next 4 lines for debugging output
# exec 5> >(logger -t $0)
@@ -10,7 +6,6 @@
# PS4='$LINENO: '
# set -x
-# default locations for setup
SCRIPTLOC=/usr/local/bin/rsyncshot;
DESTINATION=/media/backup;
@@ -20,28 +15,24 @@ LOGHOME=/var/log/rsyncshot.log;
INCLUDES="$INSTALLHOME/include.txt";
EXCLUDES="$INSTALLHOME/exclude.txt";
-# default cron job entries
-# hourly -- hourly on minute 0 from 1am to 11pm
CRON_H="0 1-23 * * * $SCRIPTLOC hourly 22";
-# daily -- midnight, Monday - Saturday.
CRON_D="0 0 * * 1-6 $SCRIPTLOC daily 6";
-# weekly -- Sundays at midnight
CRON_W="0 0 * * 7 $SCRIPTLOC weekly 51";
-# print help
help()
{
echo ""
echo "rsyncshot - compact snapshots on Linux using rsync and hard links."
+ echo ""
+ echo "rsyncshot must be run as root"
+ echo ""
echo "Usage: "
echo "rsyncshot <name> <number of backups to retain>"
echo " setup (installs rsyncshot and cron jobs)"
echo " help (prints this info)"
echo "Notes:"
echo "- install and log locations defined in script."
-}
-# display error and exit
error()
{
echo "ERROR: $0: $@" 1>&2;
@@ -49,7 +40,6 @@ error()
exit 1;
}
-# copy files, create exclude, and setup cron job
setup()
{
# copy this file to directory on path
@@ -82,27 +72,19 @@ setup()
echo "hourly, daily, and weekly cron jobs installed.";
}
-# if user requested help, display and exit.
if [ "$TYPE" = "HELP" ]; then help; exit; fi
-# ensure running as root
if [ "$EUID" -ne 0 ]; then error "This script must be run as root."; fi
-# display how the script was started
echo "rsyncshot invoked on `date -u` with: $0 $1 $2";
-# validate first arg is alpha chars and make it case insensitive
if ! [[ $1 =~ [a-zA-Z] ]]; then error "snapshot type not recognized."; fi
TYPE=$(tr '[a-z]' '[A-Z]' <<< $1);
-
-# if user requested setup, and exit.
if [ "$TYPE" = "SETUP" ]; then setup; exit; fi
-# Validate second arg is numeric
if ! [[ $2 =~ [0-9] ]]; then error "max snapshots not a number."; fi
MAX=$(($2-1));
-# validate include file (source directories)
if [ ! -f "$INCLUDES" ]; then error "include file $INCLUDES not found."; fi
SOURCES=$(<$INCLUDES);
for SOURCE in $SOURCES
@@ -110,10 +92,8 @@ do
if [ ! -d "$SOURCE" ]; then error "source $SOURCE not found"; fi
done
-# validate exclude file (exclusion patters)
if [ ! -f "$EXCLUDES" ]; then error "Exclude file $EXCLUDES not found."; fi
-# sync each source directories in turn
for SOURCE in $SOURCES
do
rsync -avh -i --times \
@@ -122,15 +102,10 @@ do
--update $SOURCE $DESTINATION/latest ;
done
-# update the time of latest to reflect snapshot time
-# touch $DESTINATION/latest;
-
-# delete the last snapshot if it exists
if [ -d $DESTINATION/$TYPE.$MAX ]; then
rm -rf $DESTINATION/$TYPE.$MAX;
fi
-# rotate snapshots descending
for (( start=$(($MAX)); start>=0; start--)); do
end=$(($start+1));
if [ -d $DESTINATION/$TYPE.$start ]; then
@@ -138,15 +113,11 @@ for (( start=$(($MAX)); start>=0; start--)); do
fi
done
-# touch the directory for a timestamp
touch $DESTINATION/latest
-# make a hard-link-only copy into $TYPE.0
cp -al $DESTINATION/latest $DESTINATION/$TYPE.0;
-# make the directory $TYPE.0 read-only
chmod -w $DESTINATION/$TYPE.0
-# print end time and exit
echo "rsyncshot completed `date -u` ";
exit 0;