Rename "local" directory to "first" directory

This commit is contained in:
Jeremy Gardais 2021-04-12 19:16:03 +02:00
parent 1ebd39d86a
commit 47cab2c053
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 26 additions and 26 deletions

View File

@ -15,7 +15,7 @@ readonly ARGS="${*}"
readonly NBARGS="${#}" readonly NBARGS="${#}"
[ -z "${DEBUG}" ] && DEBUG=1 [ -z "${DEBUG}" ] && DEBUG=1
readonly DEFAULT_LOCAL_BKP_DIR="/etc/proxmox.pve/backup" readonly DEFAULT_FIRST_BKP_DIR="/etc/proxmox.pve/backup"
readonly TODAY_VAR=$(date +%Y%m%d) readonly TODAY_VAR=$(date +%Y%m%d)
readonly DEFAULT_RETENTION_TIME="7" readonly DEFAULT_RETENTION_TIME="7"
@ -29,16 +29,16 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{ usage() { # {{{
cat <<- EOF cat <<- EOF
usage: $PROGNAME [-d|-h|-l|-r] usage: $PROGNAME [-d|-f|-h|-r]
Backup /etc/pve content Backup /etc/pve content.
EXAMPLES: EXAMPLES:
- Backup /etc/pve content to ${DEFAULT_LOCAL_BKP_DIR} directory - Backup /etc/pve content to ${DEFAULT_FIRST_BKP_DIR} directory
${PROGNAME} ${PROGNAME}
- Backup /etc/pve content to /var/backups/pve directory - Backup /etc/pve content to /var/backups/pve directory
${PROGNAME} --local /var/backups/pve ${PROGNAME} --first /var/backups/pve
- Backup to default path and keep backups for 14 days - Backup to default path and keep backups for 14 days
${PROGNAME} --retention 14 ${PROGNAME} --retention 14
@ -47,13 +47,13 @@ OPTIONS:
-d,--debug -d,--debug
Enable debug messages. Enable debug messages.
-f,--first,--first-directory
Path to a first directory to store backup
And override default path ${DEFAULT_FIRST_BKP_DIR}.
-h,--help -h,--help
Print this help message. Print this help message.
-l,--local
Path to a local directory to store backup and override
default path (${DEFAULT_LOCAL_BKP_DIR}).
-r,--retention,--retention-time -r,--retention,--retention-time
Backups older than retention time (default: ${DEFAULT_RETENTION_TIME}) Backups older than retention time (default: ${DEFAULT_RETENTION_TIME})
will be delete. will be delete.
@ -74,10 +74,10 @@ debug_message() { # {{{
# }}} # }}}
define_vars() { # {{{ define_vars() { # {{{
## If local_bkp_dir wasn't defined {{{ ## If first_bkp_dir wasn't defined {{{
if [ -z "${local_bkp_dir}" ]; then if [ -z "${first_bkp_dir}" ]; then
## Use default path to store backup ## Use default path to store backup
local_bkp_dir="${DEFAULT_LOCAL_BKP_DIR}" first_bkp_dir="${DEFAULT_FIRST_BKP_DIR}"
fi fi
## }}} ## }}}
## If retention_time wasn't defined {{{ ## If retention_time wasn't defined {{{
@ -126,28 +126,28 @@ main() { # {{{
## }}} ## }}}
## Verify if the local destination directory is absent {{{ ## Verify if the local destination directory is absent {{{
### AND create it ### AND create it
is_directory_absent "${local_bkp_dir}" \ is_directory_absent "${first_bkp_dir}" \
&& mkdir -p -- ${local_bkp_dir} && mkdir -p -- ${first_bkp_dir}
## }}} ## }}}
## Create an archive of /etc/pve to $local_bkp_dir {{{ ## Create an archive of /etc/pve to $first_bkp_dir {{{
### OR exit with error code 2 if it fails ### OR exit with error code 2 if it fails
tar czf "${local_bkp_dir}/pve.${TODAY_VAR}.tar.gz" -C /etc/ pve/ \ tar czf "${first_bkp_dir}/pve.${TODAY_VAR}.tar.gz" -C /etc/ pve/ \
|| exit 2 || exit 2
## }}} ## }}}
## Create an hard link to pve.latest.tar.gz {{{ ## Create an hard link to pve.latest.tar.gz {{{
### OR exit with error code 3 if it fails ### OR exit with error code 3 if it fails
ln --force -- "${local_bkp_dir}/pve.${TODAY_VAR}.tar.gz" "${local_bkp_dir}/pve.latest.tar.gz" \ ln --force -- "${first_bkp_dir}/pve.${TODAY_VAR}.tar.gz" "${first_bkp_dir}/pve.latest.tar.gz" \
|| exit 3 || exit 3
## }}} ## }}}
## Fix backups permissions {{{ ## Fix backups permissions {{{
### Only readable by backup (user) and adm (group) ### Only readable by backup (user) and adm (group)
chown -R backup:adm -- "${local_bkp_dir}" \ chown -R backup:adm -- "${first_bkp_dir}" \
&& chmod 'u+rwX,g+rX,o-rwx' -R -- "${local_bkp_dir}" && chmod 'u+rwX,g+rX,o-rwx' -R -- "${first_bkp_dir}"
## }}} ## }}}
## Clean files older than $retention_time {{{ ## Clean files older than $retention_time {{{
### OR exit with error code 4 if it fails ### OR exit with error code 4 if it fails
find "${local_bkp_dir}" -maxdepth 1 -type f -mtime +"${retention_time}" -iname "pve.*.tar.gz" -delete \ find "${first_bkp_dir}" -maxdepth 1 -type f -mtime +"${retention_time}" -iname "pve.*.tar.gz" -delete \
|| exit 4 || exit 4
## }}} ## }}}
@ -179,17 +179,17 @@ if [ ! "${NBARGS}" -eq "0" ]; then
-d|--debug ) ## debug -d|--debug ) ## debug
DEBUG=0 DEBUG=0
;; ;;
-f|--first,--first-directory ) ## first directory to store backup
## Move to the next argument
shift
## Define first_bkp_dir
first_bkp_dir="${1}"
;;
-h|--help ) ## help -h|--help ) ## help
usage usage
## Exit after help informations ## Exit after help informations
exit 0 exit 0
;; ;;
-l|--local ) ## local directory to store backup
## Move to the next argument
shift
## Define local_bkp_dir
local_bkp_dir="${1}"
;;
-r|--retention,--retention-time ) ## clean backups older than retention time -r|--retention,--retention-time ) ## clean backups older than retention time
## Move to the next argument ## Move to the next argument
shift shift