]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
add option to set custom backupdir and make link to latest global instead of daily
authorDimitri Bulgakov <dimitri.bulgakov@pixelpark.com>
Tue, 21 May 2019 13:13:06 +0000 (15:13 +0200)
committerDimitri Bulgakov <dimitri.bulgakov@pixelpark.com>
Tue, 21 May 2019 13:13:06 +0000 (15:13 +0200)
bin/backup_pgsql.sh

index 0efbaea9100027e1ae784504d522b5c492179890..1c778cea7d46b2eb818d72af55fac86c5b72eb74 100755 (executable)
@@ -17,7 +17,7 @@
 ###########################
 #
 #   * It stores all backup copies in directory '/var/vmail/backup' by default,
-#     You can change it in variable $BACKUP_ROOTDIR below.
+#     You can change it in variable $BACKUP_ROOTDIR below or via the -b parameter.
 #
 #   * Set correct values for below variables:
 #
@@ -145,12 +145,13 @@ description() {
 #------------------------------------------------------------------------------
 usage() {
     cat <<-EOF
-       Usage: ${BASENAME} [-K DAYS|--keep=DAYS] [-d|--debug] [[-v|--verbose] | [-q|--quiet]]] [--nocolor]
+       Usage: ${BASENAME} [-K DAYS|--keep=DAYS] [-b DIR|--backupdir=DIR] [-d|--debug] [[-v|--verbose] | [-q|--quiet]]] [--nocolor]
               ${BASENAME} [-h|--help]
               ${BASENAME} [-V|--version]
 
            Options:
                -K|--keep DAYS  Keep the backup files of the last DAYS. Default: ${KEEP_DAYS} days.
+               -b|--backupdir DIR Set backup directory. Sets backup rootdir to the same. Default today: ${BACKUP_DIR}
                -d|--debug      Debug output (bash -x).
                -v|--verbose    Set verbosity on. Mutually exclusive to '--quiet'.
                -q|--quiet      Quiet execution, only errors and warnings are shown.
@@ -190,6 +191,12 @@ get_options() {
                 shift
                 shift
                 ;;
+            -b|--backupdir)
+                BACKUP_DIR="$2"
+                BACKUP_ROOTDIR="$2"
+                shift
+                shift
+                ;;
             -d|--debug)
                 DEBUG="y"
                 shift
@@ -474,7 +481,7 @@ backup_globals() {
     local out_sql_tmp_compressed="${TMP_DIR}/${output_sql_compressed}"
     local out_sql_tgt="${BACKUP_DIR}/${output_sql}"
     local out_sql_tgt_compressed="${BACKUP_DIR}/${output_sql_compressed}"
-    local out_sql_tgt_latest="${BACKUP_DIR}/globals-latest.sql.bz2"
+    local out_sql_tgt_latest="${BACKUP_ROOTDIR}/globals-latest.sql.bz2"
 
     local verbose_option=""
     if [[ "${VERBOSE}" == "y" ]] ; then
@@ -547,7 +554,7 @@ backup_database() {
     local out_sql_tmp_compressed="${TMP_DIR}/${output_sql_compressed}"
     local out_sql_tgt="${BACKUP_DIR}/${output_sql}"
     local out_sql_tgt_compressed="${BACKUP_DIR}/${output_sql_compressed}"
-    local out_sql_tgt_latest="${BACKUP_DIR}/${db}-latest.sql.bz2"
+    local out_sql_tgt_latest="${BACKUP_ROOTDIR}/${db}-latest.sql.bz2"
 
     local verbose_option=""
     if [[ "${VERBOSE}" == "y" ]] ; then