Browse Source

fcn-backup: ajoute REMOTE_DIR pour spécifier un répertoire distant différent du répertoire local, et inclu BACKUP_DIR_INCL

Guillaume 7 years ago
parent
commit
945f2c9d90
2 changed files with 17 additions and 9 deletions
  1. 1 0
      backup.cfg.example
  2. 16 9
      fcn-backup

+ 1 - 0
backup.cfg.example

@@ -8,6 +8,7 @@ LOCAL_DIR=/var/backups
 REMOTE_ENABLE=true
 REMOTE_ENABLE=true
 REMOTE_USER=backupuser
 REMOTE_USER=backupuser
 REMOTE_HOSTNAME=backupotron5000.example.net
 REMOTE_HOSTNAME=backupotron5000.example.net
+REMOTE_DIR=/var/backups
 
 
 # PostgreSQL backup options
 # PostgreSQL backup options
 #PGSQL_EXCLUDE_DATNAME="['template_']"
 #PGSQL_EXCLUDE_DATNAME="['template_']"

+ 16 - 9
fcn-backup

@@ -26,6 +26,11 @@ elif [ ${REMOTE_ENABLE} = true ]; then
     exit 1;
     exit 1;
   fi
   fi
 
 
+  if [ -z "${REMOTE_DIR}" ]; then
+    echo >&2 "REMOTE_DIR is not set.  Aborting.";
+    exit 1;
+  fi
+
 fi
 fi
 
 
 if [ -z "${PGSQL_EXCLUDE_DATNAME}" ]; then
 if [ -z "${PGSQL_EXCLUDE_DATNAME}" ]; then
@@ -33,7 +38,7 @@ if [ -z "${PGSQL_EXCLUDE_DATNAME}" ]; then
 fi
 fi
 
 
 HOSTNAME=`hostname`
 HOSTNAME=`hostname`
-BACKUP_DEST=${LOCAL_DIR}/${HOSTNAME}.borg
+LOCAL_DEST=${LOCAL_DIR}/${HOSTNAME}.borg
 
 
 DATE=`date +%Y-%m-%d`
 DATE=`date +%Y-%m-%d`
 BACKUP_NAME="${HOSTNAME}_${DATE}"
 BACKUP_NAME="${HOSTNAME}_${DATE}"
@@ -73,28 +78,30 @@ if type "pg_dump" > /dev/null; then
   fi
   fi
 fi
 fi
 
 
-if [ ! -d "${BACKUP_DEST}" ]; then
+if [ ! -d "${LOCAL_DEST}" ]; then
   # Initialize local borg repository
   # Initialize local borg repository
-  borg init --encryption=none "${BACKUP_DEST}"
+  borg init --encryption=none "${LOCAL_DEST}"
 fi
 fi
 
 
 # Do local backup
 # Do local backup
-borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${BACKUP_DEST}::${BACKUP_NAME} "${BACKUP_TEMP}" ${BACKUP_DIR_INCL}
+borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${LOCAL_DEST}::${BACKUP_NAME} "${BACKUP_TEMP}" ${BACKUP_DIR_INCL}
 
 
 # Prune local archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
 # Prune local archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
-borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${BACKUP_DEST}
+borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${LOCAL_DEST}
 
 
 if [ ${REMOTE_ENABLE} = true ]; then
 if [ ${REMOTE_ENABLE} = true ]; then
 
 
+  REMOTE_DEST=${REMOTE_DIR}/${HOSTNAME}.borg
+
   # Quick check of the remote repository before doing a remote backup
   # Quick check of the remote repository before doing a remote backup
-  if borg check --repository-only ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}; then
+  if borg check --repository-only ${REMOTE_USER}@${REMOTE_HOSTNAME}:${REMOTE_DEST}; then
     # Do remote backup
     # Do remote backup
-    borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}::${BACKUP_NAME} "/etc" "${BACKUP_TEMP}"
+    borg create --exclude-from /etc/fcn-toolbox/backup.exclude ${REMOTE_USER}@${REMOTE_HOSTNAME}:${REMOTE_DEST}::${BACKUP_NAME} "${BACKUP_TEMP}" ${BACKUP_DIR_INCL}
     # Prune remote archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
     # Prune remote archives to keep only 7 daily, and 4 weekly, and 3 monthly ones
-    borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}
+    borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=3 ${REMOTE_USER}@${REMOTE_HOSTNAME}:${REMOTE_DEST}
   else
   else
     echo >&2 "Remote repository is missing of corrupted. Try running: "
     echo >&2 "Remote repository is missing of corrupted. Try running: "
-    echo >&2 "borg init --encryption=none ${REMOTE_USER}@${REMOTE_HOSTNAME}:${BACKUP_DEST}"
+    echo >&2 "borg init --encryption=none ${REMOTE_USER}@${REMOTE_HOSTNAME}:${REMOTE_DEST}"
   fi
   fi
 
 
 fi
 fi