about summary refs log tree commit diff stats
path: root/core/scripts/backup-system.sh
diff options
context:
space:
mode:
Diffstat (limited to 'core/scripts/backup-system.sh')
-rw-r--r--core/scripts/backup-system.sh122
1 files changed, 96 insertions, 26 deletions
diff --git a/core/scripts/backup-system.sh b/core/scripts/backup-system.sh
index 379e449..2bced8a 100644
--- a/core/scripts/backup-system.sh
+++ b/core/scripts/backup-system.sh
@@ -1,55 +1,125 @@
 #!/bin/sh
 
-echo -n "root directory you want backup (/mnt/): "
-read ROOT_DIR
+ConfirmOrExit ()
+{
+    while true
+    do
+        echo -n "Please confirm (y or n) :"
+        read CONFIRM
+        case $CONFIRM in
+            y|Y|YES|yes|Yes) break ;;
+            n|N|no|NO|No)
+                echo "Aborting - you entered $CONFIRM"
+                exit
+                ;;
+            *) echo "Please enter only y or n"
+        esac
+    done
+    echo "You entered $CONFIRM. Continuing ..."
+}
 
-echo -n "where you want to save (/home/user): "
-read DEST_DIR
+mkbk_metadata() {
+
+    # must be using gwak instead of sed, xargs and echo
+    prt-get listinst -v | sed -s s/" "/#/g | xargs -i echo {}.pkg.tar.gz > ${DEST_DIR}/installed.pkg
+
+    # make list and copy installed core packages
+    prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/core" | cut -d " " -f 3 > ${DEST_DIR}/core.pkg
+
+    prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/opt" | cut -d " " -f 3 > $DEST_DIR/opt.pkg
+
+    prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/contrib" | cut -d " " -f 3 > $DEST_DIR/contrib.pkg
 
-bk_coll() {
+    prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/xorg" | cut -d " " -f 3 > $DEST_DIR/xorg.pkg
+
+    prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep -v "yes /usr/ports/core" | grep -v "yes /usr/ports/opt" | grep -v "yes /usr/ports/contrib" | grep -v "yes /usr/ports/xorg" | grep "yes " | cut -d " " -f 3 > $DEST_DIR/other.pkg
+
+}
+
+mkbk_coll_pkg() {
     col=$1
     # make copy of packages
-    mkdir ${BKDIR}/${col}
+    mkdir ${PORT_PKG}/${col}
     while read line; do
             if [ ! -f /usr/ports/packages/${line} ]; then
                 echo "Building package: ${line};\n"
                 name=$(echo ${line} | cut -d "#" -f 1)
-                sudo prt-get update -fr ${name}
+                #$sudo prt-get update -fr ${name}
             fi
 
             if [ -f /usr/ports/packages/${line} ]; then
                 echo "Backing up package: ${line}"
-                echo ${line} >> ${BKDIR}/backup.pkg
-                cp /usr/ports/packages/${line} ${BKDIR}/${col}/
+                echo ${line} >> ${DEST_DIR}/backup.pkg
+                cp /usr/ports/packages/${line} ${PORT_PKG}/${col}/
             else
                 echo "Package not found: ${line}"
-                echo ${line} >> ${BKDIR}/${col}-notfound.pkg
+                echo ${line} >> ${DEST_DIR}/${col}-notfound.pkg
             fi
-    done < $BKDIR/${col}.pkg
+    done < $DEST_DIR/${col}.pkg
 }
 
-# Temporary directory
-BKDIR=$(pwd)/bkdir
-mkdir -p ${BKDIR}
+mkbk_coll_ports() {
+    col=$1
 
-# must be using gwak instead of sed, xargs and echo
-prt-get listinst -v | sed -s s/" "/#/g | xargs -i echo {}.pkg.tar.gz > ${BKDIR}/installed.pkg
+#    tar --xattrs -zcpf $PORT_PRT/${col}-`date '+%Y-%j-%H-%M-%S'`.tar.gz \
+#    --directory=$ROOT_DIR/usr/ports/${col} \
+#    .
+    tar --xattrs -zcpf $PORT_PRT/${col}.tar.gz \
+    --directory=$ROOT_DIR/usr/ports/${col} \
+    --exclude=.git/ \
+    .
+
+}
+
+mkbk_data_conf() {
+
+    tar --xattrs -zcpf $DATA_CNF/etc.tar.gz \
+        --directory=$ROOT_DIR/etc \
+        .
+
+    tar --xattrs -zcpf $DATA_CNF/usr_etc.tar.gz \
+        --directory=$ROOT_DIR/usr/etc \
+        .
+}
+
+
+echo -n "root directory you want backup (/mnt/): "
+#read ROOT_DIR
+ROOT_DIR=$1
+
+echo -n "where you want to save (/home/user): "
+DEST_DIR=$2
+
+# Temporary directory
+PORT_PKG="${DEST_DIR}/crux"
+PORT_PRT="${DEST_DIR}/ports"
+DATA_CNF="${DEST_DIR}/conf"
 
-# make list and copy installed core packages
-prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/core" | cut -d " " -f 3 > ${BKDIR}/core.pkg
-bk_coll "core"
+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}"
 
+ConfirmOrExit
 
-prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/opt" | cut -d " " -f 3 > $BKDIR/opt.pkg
-bk_coll "opt"
+mkdir -p ${PORT_PKG}
+mkdir -p ${PORT_PRT}
+mkdir -p ${DATA_CNF}
 
-prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/contrib" | cut -d " " -f 3 > $BKDIR/contrib.pkg
-bk_coll "contrib"
+mkbk_metadata
+mkbk_data_conf
 
-prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/xorg" | cut -d " " -f 3 > $BKDIR/xorg.pkg
-bk_coll "xorg"
+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"
 
-prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep -v "yes /usr/ports/core" | grep -v "yes /usr/ports/opt" | grep -v "yes /usr/ports/contrib" | grep -v "yes /usr/ports/xorg" | grep "yes " | cut -d " " -f 3 > $BKDIR/other.pkg
+mkbk_coll_pkg "other"
 
 #echo $DES_DIR
 #echo $ROOT_DIR