summaryrefslogtreecommitdiff
path: root/backup_simple
diff options
context:
space:
mode:
authorgrothedev <grothedev@gmail.com>2021-10-08 12:38:36 -0500
committergrothedev <grothedev@gmail.com>2021-10-08 12:38:36 -0500
commit9567428e99acb1689ddfe2a6ffba8a675cbafa93 (patch)
tree877a1c72929612dacc3272e03335af117a388b3b /backup_simple
parentf3e8b39ac81340129288f1180511bf37f40cba35 (diff)
a bunch of updates
Diffstat (limited to 'backup_simple')
-rwxr-xr-xbackup_simple34
1 files changed, 23 insertions, 11 deletions
diff --git a/backup_simple b/backup_simple
index 0685e6e..9bdcc88 100755
--- a/backup_simple
+++ b/backup_simple
@@ -2,6 +2,11 @@
#a simple backup script that uses rsync
+#arg 1: source path: the path to backup.
+#arg 2 (optional): destination path: absolute path on host to put src
+#arg 3: rsync args
+#if no destination given, src will be pushed to the given src inside of path described by ${HB_BACKUP_DIR} env var, if it exists, otherwise it will be inside of remote user's home dir
+
d=`date +%Y-%m-%d_%H:%M:%S`
if [[ -z $1 ]]; then
@@ -9,14 +14,20 @@ if [[ -z $1 ]]; then
exit 0
fi
-src="$1"
+src_path="$1"
#dest='hb:/var/stor/personal/backup/'
-dest="hb:"$HB_BACKUP_DIR
+dest_host="hb"
+if [[ $HB_BACKUP_DIR ]]; then
+ dest_path=$HB_BACKUP_DIR"/"${src_path}
+else
+ dest_path="~/"${src_path}
+fi
+
rsargs=''
if [[ $2 ]]; then
echo 'using destination '${2}
- dest="thomas@hb:"${2}
+ dest_path=${2}
fi
if [[ $3 ]]; then
@@ -24,14 +35,15 @@ if [[ $3 ]]; then
rsargs=${@}
fi
-
-remote_host=`echo $dest | cut -f1 -d':'`
-#dest_path_dir=`echo $dest | cut -f2 -d':' | sed 's,\(.*\)\/$,\1\/,g'` #directory right above the file/directory of interest
-dest_path_dir=`echo $dest | sed 's,\(.*\)\/.*,\1\/,g'` #directory right above the file/directory of interest
-
-
-echo "NEW BACKUP "$d" ${src} -> ${dest}" >> /var/log/datasync.log
-rsync -arvzP --protect-args -e ssh --update ${src} ${dest} ${rsargs} >> /var/log/datasync.log
+dest=$dest_host":"$dest_path
+if [[ ${dest_path: -1} == "/" ]]; then
+ ssh hb mkdir -p ${dest_path}
+else
+ dest_parent_dir=`echo $dest_path | rev | cut -d'/' -f2- | rev`
+ ssh hb mkdir -p ${dest_parent_dir}
+fi
+echo "NEW BACKUP $d ${src_path} -> ${dest}" >> /var/log/datasync.log
+rsync -arvzP --protect-args -e ssh --update ${src_path} ${dest} ${rsargs} >> /var/log/datasync.log
echo "" >> /var/log/datasync.log