From 470ccadc39b83c0d65563d6d71773301c1aba0e8 Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 14:49:58 -0400 Subject: [PATCH 1/9] remove email design goal from README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c4b1a11..c4f30ea 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Wrapper script for rsync to export files to one or more USB backup drive(s). - crontab entry should be as simple as /usr/local/bin/rsync2usb - need an install script to create the symlink in /usr/local/bin - need an uninstall script to remove the symlink in /usr/local/bin -- script should capture output and email to admins on error - check for USB drive running out of space - automount / encryption is handled by autofs and LUKS, not this package - use a lock file to control access to USB drive From 7100a50fdf95b0c5ff9a7d0b471f7d2f3cfa8f09 Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 14:52:16 -0400 Subject: [PATCH 2/9] remove dependency on mailx from README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4f30ea..dcb917d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Wrapper script for rsync to export files to one or more USB backup drive(s). - use a lock file to control access to USB drive - allow for multiple backup paths to be specified (one chosen at random) - needs to work on RHEL5, CentoOS6 and Cygwin64 at a minimum -- depends on the mailx command and rsync command +- depends on the rsync command From 3152196a2f465301916f282e541a52f80c164d84 Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 14:56:43 -0400 Subject: [PATCH 3/9] rename main script to just sync2usb --- sync2usb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 sync2usb diff --git a/sync2usb b/sync2usb new file mode 100755 index 0000000..d4af6b5 --- /dev/null +++ b/sync2usb @@ -0,0 +1,10 @@ +#!/bin/bash + +# exit immediately on errors +set -e +# error out if uninitialized variable is used +set -u + + + + From dded818ec70a4140a512fa45f5cfe7d4782ef4fb Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 14:57:04 -0400 Subject: [PATCH 4/9] create experiments folder --- rsync2usb | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100755 rsync2usb diff --git a/rsync2usb b/rsync2usb deleted file mode 100755 index d4af6b5..0000000 --- a/rsync2usb +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# exit immediately on errors -set -e -# error out if uninitialized variable is used -set -u - - - - From fed8a5973579617b0cc01e4adf8ade2bb75480d3 Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 15:18:34 -0400 Subject: [PATCH 5/9] defining global/user/job variables --- sync2usb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sync2usb b/sync2usb index d4af6b5..c4de44f 100755 --- a/sync2usb +++ b/sync2usb @@ -5,6 +5,25 @@ set -e # error out if uninitialized variable is used set -u +# Configuration Variables: +# +# GLOBAL / USER: +# +# lvm_snapshotadd - Amount (in GiB) to add to the LV when doing the snapshot +# lvm_thinflag - (possibly not needed), 'true' if LV is a "thin" LV +# lvm_vgname - Volume Group name which contains the LV (optional) +# minimum_free_space - Measured in GiB (gigabytes), error if target has less, warn at 2x or less +# minimum_free_inodes - Error if target file system has less, warn at 2x or less +# usb_base - directory where USB backup drives are mounted +# usb_prefix - space delimited list of letters/numbers used as prefixes +# usb_filename - the unchanging portion of the mount directory +# usb_suffix - space delimited list of letters/numbers used as suffixes +# +# JOB SPECIFIC: +# +# backup_dir - Backup directory +# lvm_lvname - Logical Volume name of the backup_base directory (optional) +declare -a From 01da8abe13c818bf3b04576ad478e0984466613b Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 15:21:29 -0400 Subject: [PATCH 6/9] create arrays to hold variable names --- sync2usb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sync2usb b/sync2usb index c4de44f..e00b6d4 100755 --- a/sync2usb +++ b/sync2usb @@ -24,6 +24,13 @@ set -u # backup_dir - Backup directory # lvm_lvname - Logical Volume name of the backup_base directory (optional) -declare -a - +declare -a GlobalConfigVariables=( \ + 'lvm_snapshotadd', 'lvm_thinflag', 'lvm_vgname', \ + 'minimum_free_space', 'minimum_free_inodes', \ + 'usb_base', 'usb_prefix', 'usb_filename', 'usb_suffix', \ + ); +declare -a JobSpecificVariables=( \ + 'backup_dir', + 'lvm_lvname' \ + ); From 9a4f3ec18cc503929146fed8a6f9840546042fca Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 15:42:09 -0400 Subject: [PATCH 7/9] setting up variables, set defaults, debug lines --- sync2usb | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/sync2usb b/sync2usb index e00b6d4..9e32541 100755 --- a/sync2usb +++ b/sync2usb @@ -9,6 +9,7 @@ set -u # # GLOBAL / USER: # +# job_directory - location of job files # lvm_snapshotadd - Amount (in GiB) to add to the LV when doing the snapshot # lvm_thinflag - (possibly not needed), 'true' if LV is a "thin" LV # lvm_vgname - Volume Group name which contains the LV (optional) @@ -24,13 +25,38 @@ set -u # backup_dir - Backup directory # lvm_lvname - Logical Volume name of the backup_base directory (optional) -declare -a GlobalConfigVariables=( \ - 'lvm_snapshotadd', 'lvm_thinflag', 'lvm_vgname', \ - 'minimum_free_space', 'minimum_free_inodes', \ - 'usb_base', 'usb_prefix', 'usb_filename', 'usb_suffix', \ +declare -a GlobalConfigVariables=( + 'job_directory' + 'lvm_snapshotadd' 'lvm_thinflag' 'lvm_vgname' + 'minimum_free_space' 'minimum_free_inodes' + 'usb_base' 'usb_prefix' 'usb_filename' 'usb_suffix' ); -declare -a JobSpecificVariables=( \ - 'backup_dir', - 'lvm_lvname' \ +declare -a JobSpecificVariables=( + 'backup_dir' + 'lvm_lvname' ); +# Set default values +backup_dir="" +job_directory="/etc/sync2usb.d/" +lvm_lvname="" +lvm_snapshotadd=10 +lvm_thinflag=true +lvm_vgname="" +minimum_free_space=25 +minimum_free_inodes=50000 +usb_base="/mnt/" +usb_prefix="" +usb_filename="BACKUP" +usb_suffix="1 2 3 4 5 6 7 8 9" + +echo ${GlobalConfigVariables[@]} +echo ${JobSpecificVariables[@]} + +for x in ${GlobalConfigVariables[@]}; do + eval GCV=\$$x + echo "${x}=${GCV}" +done + + + From 3ce54cc486f9c0e7c3af1d12098a517d0eb1a98e Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 15:51:14 -0400 Subject: [PATCH 8/9] dump initial default variable values if verbosity>=2 --- sync2usb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sync2usb b/sync2usb index 9e32541..597443e 100755 --- a/sync2usb +++ b/sync2usb @@ -30,11 +30,13 @@ declare -a GlobalConfigVariables=( 'lvm_snapshotadd' 'lvm_thinflag' 'lvm_vgname' 'minimum_free_space' 'minimum_free_inodes' 'usb_base' 'usb_prefix' 'usb_filename' 'usb_suffix' + 'verbosity' ); declare -a JobSpecificVariables=( 'backup_dir' 'lvm_lvname' ); +AllVariables=("${GlobalConfigVariables[@]}" "${JobSpecificVariables[@]}") # Set default values backup_dir="" @@ -49,14 +51,14 @@ usb_base="/mnt/" usb_prefix="" usb_filename="BACKUP" usb_suffix="1 2 3 4 5 6 7 8 9" +verbosity=2 -echo ${GlobalConfigVariables[@]} -echo ${JobSpecificVariables[@]} - -for x in ${GlobalConfigVariables[@]}; do - eval GCV=\$$x - echo "${x}=${GCV}" -done - +if [ "$verbosity" -ge "2" ]; then + echo "Default Configuration Variables:" + for DefaultVariableName in ${AllVariables[@]}; do + eval VerboseListVariableDefaultValue=\$$DefaultVariableName + echo "${DefaultVariableName}=${VerboseListVariableDefaultValue}" + done +fi From 8f9f6a5573c82650a5e999435bf5de0765bb86a0 Mon Sep 17 00:00:00 2001 From: Thomas Harold Date: Thu, 6 Aug 2015 16:03:47 -0400 Subject: [PATCH 9/9] creating read_config_file function --- sync2usb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sync2usb b/sync2usb index 597443e..ec24ca2 100755 --- a/sync2usb +++ b/sync2usb @@ -19,6 +19,7 @@ set -u # usb_prefix - space delimited list of letters/numbers used as prefixes # usb_filename - the unchanging portion of the mount directory # usb_suffix - space delimited list of letters/numbers used as suffixes +# verbosity - 0=none, 1=some info, 2=debug level # # JOB SPECIFIC: # @@ -61,4 +62,16 @@ if [ "$verbosity" -ge "2" ]; then done fi +GlobalConfigFilename="/etc/sync2usb.conf" +UserConfigFilename="~/.sync2usb" + +# read a configuration file +# $1 - filename (full path) +read_config_file () +{ + echo "Reading config file: $1" +} + +read_config_file ${GlobalConfigFilename} +read_config_file ${UserConfigFilename}