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