Allow to override default owner and group of backup files

This commit is contained in:
Jeremy Gardais 2021-04-14 10:11:54 +02:00
parent 0fc60ef863
commit d1b2bc5e48
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 24 additions and 4 deletions

View File

@ -4,7 +4,7 @@
# 1. Make an archive to a first directory (default: /etc/proxmox.pve/backup/). # 1. Make an archive to a first directory (default: /etc/proxmox.pve/backup/).
# 2. Hard link a fix archive name (pve.latest.tar.gz) to new archive # 2. Hard link a fix archive name (pve.latest.tar.gz) to new archive
# Easy to monitor (eg. this path can be expected). # Easy to monitor (eg. this path can be expected).
# 3. Limit permissions to backup directory (backup:adm). # 3. Limit permissions to backup directory (default: backup:adm).
# 4. Clean backups older than retention time (default: 7). # 4. Clean backups older than retention time (default: 7).
# 5. (optionnal) Copy backup to a second directory (nfs mountpoint, other hdd,…). # 5. (optionnal) Copy backup to a second directory (nfs mountpoint, other hdd,…).
# #
@ -21,6 +21,8 @@ readonly NBARGS="${#}"
readonly DEFAULT_FIRST_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"
readonly DEFAULT_USER="backup"
readonly DEFAULT_GROUP="adm"
## Colors ## Colors
readonly PURPLE='\033[1;35m' readonly PURPLE='\033[1;35m'
@ -32,7 +34,7 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{ usage() { # {{{
cat <<- EOF cat <<- EOF
usage: $PROGNAME [-d|-f|-h|-r|-s] usage: $PROGNAME [-d|-f|-g|-h|-r|-s|-u]
Backup /etc/pve content. Backup /etc/pve content.
@ -57,6 +59,9 @@ OPTIONS:
Path to a first directory to store backup Path to a first directory to store backup
And override default path ${DEFAULT_FIRST_BKP_DIR}. And override default path ${DEFAULT_FIRST_BKP_DIR}.
-g,--group
Group of the backup files (default: ${DEFAULT_GROUP}).
-h,--help -h,--help
Print this help message. Print this help message.
@ -67,6 +72,9 @@ OPTIONS:
-s,--second,--second-directory -s,--second,--second-directory
Path to a second directory to duplicate backups (default: not set). Path to a second directory to duplicate backups (default: not set).
-u,--user
Owner of the backup files (default: ${DEFAULT_USER}).
EOF EOF
} }
@ -150,8 +158,8 @@ main() { # {{{
|| exit 3 || exit 3
## }}} ## }}}
## Fix backups permissions {{{ ## Fix backups permissions {{{
### Only readable by backup (user) and adm (group) ### Only readable by specified user:group (default: backup:adm)
chown -R backup:adm -- "${first_bkp_dir}" \ chown -R "${user_bkp_dir}:${group_bkp_dir}" -- "${first_bkp_dir}" \
&& chmod 'u+rwX,g+rX,o-rwx' -R -- "${first_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 {{{
@ -208,6 +216,12 @@ if [ ! "${NBARGS}" -eq "0" ]; then
## Define first_bkp_dir ## Define first_bkp_dir
first_bkp_dir="${1}" first_bkp_dir="${1}"
;; ;;
-g|--group ) ## group of backup files
## Move to the next argument
shift
## Define group_bkp_dir
group_bkp_dir="${1}"
;;
-h|--help ) ## help -h|--help ) ## help
usage usage
## Exit after help informations ## Exit after help informations
@ -225,6 +239,12 @@ if [ ! "${NBARGS}" -eq "0" ]; then
## Define second_bkp_dir ## Define second_bkp_dir
second_bkp_dir="${1}" second_bkp_dir="${1}"
;; ;;
-u|--user ) ## owner of backup files
## Move to the next argument
shift
## Define user_bkp_dir
user_bkp_dir="${1}"
;;
* ) ## unknow option * ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}" printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---" printf '%b\n' "---"