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="${#}"
[ -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 DEFAULT_RETENTION_TIME="7"
@ -29,16 +29,16 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{
cat <<- EOF
usage: $PROGNAME [-d|-h|-l|-r]
usage: $PROGNAME [-d|-f|-h|-r]
Backup /etc/pve content
Backup /etc/pve content.
EXAMPLES:
- Backup /etc/pve content to ${DEFAULT_LOCAL_BKP_DIR} directory
- Backup /etc/pve content to ${DEFAULT_FIRST_BKP_DIR} directory
${PROGNAME}
- 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
${PROGNAME} --retention 14
@ -47,13 +47,13 @@ OPTIONS:
-d,--debug
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
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
Backups older than retention time (default: ${DEFAULT_RETENTION_TIME})
will be delete.
@ -74,10 +74,10 @@ debug_message() { # {{{
# }}}
define_vars() { # {{{
## If local_bkp_dir wasn't defined {{{
if [ -z "${local_bkp_dir}" ]; then
## If first_bkp_dir wasn't defined {{{
if [ -z "${first_bkp_dir}" ]; then
## Use default path to store backup
local_bkp_dir="${DEFAULT_LOCAL_BKP_DIR}"
first_bkp_dir="${DEFAULT_FIRST_BKP_DIR}"
fi
## }}}
## If retention_time wasn't defined {{{
@ -126,28 +126,28 @@ main() { # {{{
## }}}
## Verify if the local destination directory is absent {{{
### AND create it
is_directory_absent "${local_bkp_dir}" \
&& mkdir -p -- ${local_bkp_dir}
is_directory_absent "${first_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
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
## }}}
## Create an hard link to pve.latest.tar.gz {{{
### 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
## }}}
## Fix backups permissions {{{
### Only readable by backup (user) and adm (group)
chown -R backup:adm -- "${local_bkp_dir}" \
&& chmod 'u+rwX,g+rX,o-rwx' -R -- "${local_bkp_dir}"
chown -R backup:adm -- "${first_bkp_dir}" \
&& chmod 'u+rwX,g+rX,o-rwx' -R -- "${first_bkp_dir}"
## }}}
## Clean files older than $retention_time {{{
### 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
## }}}
@ -179,17 +179,17 @@ if [ ! "${NBARGS}" -eq "0" ]; then
-d|--debug ) ## debug
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
usage
## Exit after help informations
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
## Move to the next argument
shift