summaryrefslogtreecommitdiff
path: root/backup_simple
diff options
context:
space:
mode:
authorgrothedev <grothedev@gmail.com>2021-06-12 15:36:31 -0500
committergrothedev <grothedev@gmail.com>2021-06-12 15:36:31 -0500
commit7ad82011db8c22a18a5870394e890b2cc15ecc8c (patch)
tree8b1b5537dc20d6226d2a5caf69ab2f725cba05fe /backup_simple
first commit. random and useful scripts
Diffstat (limited to 'backup_simple')
-rwxr-xr-xbackup_simple34
1 files changed, 34 insertions, 0 deletions
diff --git a/backup_simple b/backup_simple
new file mode 100755
index 0000000..a50e22d
--- /dev/null
+++ b/backup_simple
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+#a simple backup script that uses rsync
+
+if [[ -z $1 ]]; then
+ echo 'you must at least provide a source dir'
+ exit 0
+fi
+
+src=$1
+dest='hb:/var/stor/personal/backup/'
+rsargs=''
+
+if [[ $2 ]]; then
+ echo 'using destination '${2}
+ dest="thomas@hb:"${2}
+fi
+
+if [[ $3 ]]; then
+ shift 2
+ 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
+ssh ${remote_host} "mkdir -p ${dest_path_dir}"
+
+if [[ $(rsync -arvzP -e ssh --update ${src} ${dest} ${rsargs} | grep "%") ]]; then
+ echo "Complete."
+else
+ echo "!! ${src} not uploaded. Server version is newer."
+fi