about summary refs log tree commit diff stats
path: root/core/scripts/backup-system.sh
diff options
context:
space:
mode:
authorSilvino Silva <silvino@bk.ru>2018-07-17 00:07:56 +0100
committerSilvino Silva <silvino@bk.ru>2018-07-17 00:07:56 +0100
commit8e26cc1ca02691e621a82c274e9cfcd90181ccbe (patch)
treeda34dbb85daf65ed993f5b6d56847d7d37cb0cd3 /core/scripts/backup-system.sh
parentf5955b57400b065d77fc115c821c18864f3dae02 (diff)
parentfa4a1dbc55e566b6f891636ed0301bf6a188b312 (diff)
downloaddoc-8e26cc1ca02691e621a82c274e9cfcd90181ccbe.tar.gz
release 0.3.5
Diffstat (limited to 'core/scripts/backup-system.sh')
-rw-r--r--core/scripts/backup-system.sh157
1 files changed, 113 insertions, 44 deletions
diff --git a/core/scripts/backup-system.sh b/core/scripts/backup-system.sh
index 49b9873..ba6a961 100644
--- a/core/scripts/backup-system.sh
+++ b/core/scripts/backup-system.sh
@@ -1,4 +1,12 @@
-#!/bin/sh
+#!/bin/bash
+
+ROOT_DIR=
+DEST_DIR=/root/backup
+PORT_PKG="${DEST_DIR}/crux"
+PORT_PRT="${DEST_DIR}/ports"
+DATA_CNF="${DEST_DIR}/conf"
+DATA_USR="${DEST_DIR}/user"
+DATA_SRV="${DEST_DIR}/srv"
 
 ConfirmOrExit ()
 {
@@ -50,9 +58,9 @@ mkbk_coll_ports() {
         --directory=$ROOT_DIR/usr/ports/${col} \
         --exclude=.git/ \
         .
-
 }
 
+
 mkbk_metadata() {
 
     # archive pkgutils data
@@ -158,8 +166,8 @@ mkbk_user_metadata() {
 
             # encript data
             #gpg --output "${DATA_USR}/meta-${user}.tar.gz.gpg" \
-            #    --encrypt --recipient user@host \
-            #    "${DATA_USR}/meta-${user}.tar.gz"
+                #    --encrypt --recipient user@host \
+                #    "${DATA_USR}/meta-${user}.tar.gz"
 
             tar --xattrs -zcpf "${DATA_USR}/gitolite-${user}.tar.gz" \
                 $dir/gitolite-admin
@@ -167,34 +175,56 @@ mkbk_user_metadata() {
     done
 }
 
-echo -n "root directory you want backup (/mnt/):\n "
-#read ROOT_DIR
-ROOT_DIR=$1
-
-echo -n "where you want to save (/home/user):\n "
-DEST_DIR=$2
-
-# Temporary directory
-PORT_PKG="${DEST_DIR}/crux"
-PORT_PRT="${DEST_DIR}/ports"
-DATA_CNF="${DEST_DIR}/conf"
-DATA_USR="${DEST_DIR}/user"
-DATA_SRV="${DEST_DIR}/srv"
+print_data () {
+    echo "ROOT_DIR=${ROOT_DIR}"
+    echo "DEST_DIR=${DEST_DIR}"
+    echo "PORT_PKG=${PORT_PKG}"
+    echo "PORT_PRT=${PORT_PRT}"
+    echo "DATA_CNF=${DATA_CNF}"
+    echo "DATA_USR=${DATA_USR}"
+    echo "DATA_SRV=${DATA_SRV}"
+}
 
-echo "ROOT_DIR=${ROOT_DIR}"
-echo "DEST_DIR=${DEST_DIR}"
-echo "PORT_PKG=${PORT_PKG}"
-echo "PORT_PRT=${PORT_PRT}"
-echo "DATA_CNF=${DATA_CNF}"
-echo "DATA_USR=${DATA_USR}"
-echo "DATA_SRV=${DATA_SRV}"
+print_help() {
+    echo "usage: backup-system [options]"
+    echo "options:"
+    echo "  -r,   --root                root directory to backup, default /"
+    echo "  -d,   --destination         save backup, default /root/backup"
+    echo "  -h,   --help                print help and exit"
+}
 
+while [ "$1" ]; do
+    case $1 in
+        -r|--root)
+            ROOT_DIR=$2
+            if [ ${ROOT_DIR} == "/" ]; then
+                ROOT_DIR=""
+            fi
+            shift ;;
+        -d|--destination)
+            DEST_DIR=$2
+
+            # Destination directory
+            PORT_PKG="${DEST_DIR}/crux"
+            PORT_PRT="${DEST_DIR}/ports"
+            DATA_CNF="${DEST_DIR}/conf"
+            DATA_USR="${DEST_DIR}/user"
+            DATA_SRV="${DEST_DIR}/srv"
+            shift ;;
+        -h|--help)
+            print_help
+            exit 0 ;;
+        *)
+            echo "backup-system: invalid option $1"
+            print_help
+            exit 1 ;;
+    esac
+    shift
+done
+
+print_data
 ConfirmOrExit
 
-if [ ${ROOT_DIR} == "/" ]; then
-    ROOT_DIR=""
-fi
-
 mkdir -p ${PORT_PKG}
 mkdir -p ${PORT_PRT}
 mkdir -p ${DATA_CNF}
@@ -204,20 +234,59 @@ mkdir -p ${DATA_SRV}
 # Light backup data
 mkbk_metadata
 mkbk_etc_conf
-mkbk_user_metadata
-mkbk_srv_www
-mkbk_srv_pgsql
-mkbk_srv_gitolite
-
-# Port system
-mkbk_coll_ports "core"
-mkbk_coll_pkg "core"
-mkbk_coll_ports "opt"
-mkbk_coll_pkg "opt"
-mkbk_coll_ports "contrib"
-mkbk_coll_pkg "contrib"
-mkbk_coll_ports "xorg"
-mkbk_coll_pkg "xorg"
-
-mkbk_coll_pkg "other"
 
+while true
+do
+    echo -n "Backup user metadata ? Please confirm (y or n) :"
+    read CONFIRM
+    case $CONFIRM in
+        n|N|no|NO|No) break ;;
+        y|Y|YES|yes|Yes)
+            echo "Accept - you entered $CONFIRM"
+            mkbk_user_metadata
+            break
+            ;;
+        *) echo "Please enter only y or n"
+    esac
+done
+
+while true
+do
+    echo -n "Backup server data ? Please confirm (y or n) :"
+    read CONFIRM
+    case $CONFIRM in
+        n|N|no|NO|No) break ;;
+        y|Y|YES|yes|Yes)
+            echo "Accept - you entered $CONFIRM"
+            mkbk_srv_www
+            mkbk_srv_pgsql
+            mkbk_srv_gitolite
+            break
+            ;;
+        *) echo "Please enter only y or n"
+    esac
+done
+
+
+while true
+do
+    echo -n "Backup port system ? Please confirm (y or n) :"
+    read CONFIRM
+    case $CONFIRM in
+        n|N|no|NO|No) break ;;
+        y|Y|YES|yes|Yes)
+            echo "Accept - you entered $CONFIRM"
+            mkbk_coll_ports "core"
+            mkbk_coll_pkg "core"
+            mkbk_coll_ports "opt"
+            mkbk_coll_pkg "opt"
+            mkbk_coll_ports "contrib"
+            mkbk_coll_pkg "contrib"
+            mkbk_coll_ports "xorg"
+            mkbk_coll_pkg "xorg"
+            mkbk_coll_pkg "other"
+            break
+            ;;
+        *) echo "Please enter only y or n"
+    esac
+done