feat: support Rclone global flasgs (close #49)
This commit is contained in:
1
.env
1
.env
@@ -3,6 +3,7 @@
|
||||
|
||||
# RCLONE_REMOTE_NAME="BitwardenBackup"
|
||||
# RCLONE_REMOTE_DIR="/BitwardenBackup/"
|
||||
# RCLONE_GLOBAL_FLAG=""
|
||||
# CRON="5 * * * *"
|
||||
# ZIP_ENABLE="TRUE"
|
||||
# ZIP_PASSWORD="WHEREISMYPASSWORD?"
|
||||
|
||||
@@ -232,6 +232,14 @@ Folder for storing backup files in the storage system.
|
||||
|
||||
Default: `/BitwardenBackup/`
|
||||
|
||||
#### RCLONE_GLOBAL_FLAG
|
||||
|
||||
Rclone global flags, see [flags](https://rclone.org/flags/).
|
||||
|
||||
**Do not add flags that change the output, such as `-P`, which will affect the deletion of outdated backup files.**
|
||||
|
||||
Default: `''`
|
||||
|
||||
#### CRON
|
||||
|
||||
Schedule run backup script, based on Linux `crond`. You can test the rules [here](https://crontab.guru/#5_*_*_*_*).
|
||||
|
||||
@@ -232,6 +232,14 @@ Rclone 远程名称,你可以自己修改命名。
|
||||
|
||||
默认值:`/BitwardenBackup/`
|
||||
|
||||
#### RCLONE_GLOBAL_FLAG
|
||||
|
||||
Rclone 全局参数,详见 [flags](https://rclone.org/flags/)。
|
||||
|
||||
**不要添加会改变输出的全局参数,比如 `-P`,它会影响删除过期备份文件的操作。**
|
||||
|
||||
默认值:`''`
|
||||
|
||||
#### CRON
|
||||
|
||||
`crond` 的规则,它基于 Linux `crond`。你可以在 [这里](https://crontab.guru/#5_*_*_*_*) 进行测试。
|
||||
|
||||
@@ -19,6 +19,7 @@ services:
|
||||
# environment:
|
||||
# RCLONE_REMOTE_NAME: 'BitwardenBackup'
|
||||
# RCLONE_REMOTE_DIR: '/BitwardenBackup/'
|
||||
# RCLONE_GLOBAL_FLAG: ''
|
||||
# CRON: '5 * * * *'
|
||||
# ZIP_ENABLE: 'TRUE'
|
||||
# ZIP_PASSWORD: 'WHEREISMYPASSWORD?'
|
||||
|
||||
@@ -135,7 +135,7 @@ function upload() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rclone copy "${UPLOAD_FILE}" "${RCLONE_REMOTE}"
|
||||
rclone ${RCLONE_GLOBAL_FLAG} copy "${UPLOAD_FILE}" "${RCLONE_REMOTE}"
|
||||
if [[ $? != 0 ]]; then
|
||||
color red "upload failed"
|
||||
|
||||
@@ -149,13 +149,13 @@ function clear_history() {
|
||||
if [[ "${BACKUP_KEEP_DAYS}" -gt 0 ]]; then
|
||||
color blue "delete ${BACKUP_KEEP_DAYS} days ago backup files"
|
||||
|
||||
mapfile -t RCLONE_DELETE_LIST < <(rclone lsf "${RCLONE_REMOTE}" --min-age "${BACKUP_KEEP_DAYS}d")
|
||||
mapfile -t RCLONE_DELETE_LIST < <(rclone ${RCLONE_GLOBAL_FLAG} lsf "${RCLONE_REMOTE}" --min-age "${BACKUP_KEEP_DAYS}d")
|
||||
|
||||
for RCLONE_DELETE_FILE in "${RCLONE_DELETE_LIST[@]}"
|
||||
do
|
||||
color yellow "deleting \"${RCLONE_DELETE_FILE}\""
|
||||
|
||||
rclone delete "${RCLONE_REMOTE}/${RCLONE_DELETE_FILE}"
|
||||
rclone ${RCLONE_GLOBAL_FLAG} delete "${RCLONE_REMOTE}/${RCLONE_DELETE_FILE}"
|
||||
if [[ $? != 0 ]]; then
|
||||
color red "delete \"${RCLONE_DELETE_FILE}\" failed"
|
||||
fi
|
||||
|
||||
@@ -30,14 +30,14 @@ function color() {
|
||||
# None
|
||||
########################################
|
||||
function check_rclone_connection() {
|
||||
rclone config show "${RCLONE_REMOTE_NAME}" > /dev/null 2>&1
|
||||
rclone ${RCLONE_GLOBAL_FLAG} config show "${RCLONE_REMOTE_NAME}" > /dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
color red "rclone configuration information not found"
|
||||
color blue "Please configure rclone first, check https://github.com/ttionya/vaultwarden-backup/blob/master/README.md#backup"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rclone mkdir "${RCLONE_REMOTE}"
|
||||
rclone ${RCLONE_GLOBAL_FLAG} mkdir "${RCLONE_REMOTE}"
|
||||
if [[ $? != 0 ]]; then
|
||||
color red "storage system connection failure"
|
||||
exit 1
|
||||
@@ -207,6 +207,10 @@ function init_env() {
|
||||
# RCLONE_REMOTE
|
||||
RCLONE_REMOTE=$(echo "${RCLONE_REMOTE_NAME}:${RCLONE_REMOTE_DIR}" | sed 's@\(/*\)$@@')
|
||||
|
||||
# RCLONE_GLOBAL_FLAG
|
||||
get_env RCLONE_GLOBAL_FLAG
|
||||
RCLONE_GLOBAL_FLAG="${RCLONE_GLOBAL_FLAG:-""}"
|
||||
|
||||
# ZIP_ENABLE
|
||||
get_env ZIP_ENABLE
|
||||
ZIP_ENABLE=$(echo "${ZIP_ENABLE}" | tr '[a-z]' '[A-Z]')
|
||||
@@ -260,6 +264,7 @@ function init_env() {
|
||||
color yellow "RCLONE_REMOTE_NAME: ${RCLONE_REMOTE_NAME}"
|
||||
color yellow "RCLONE_REMOTE_DIR: ${RCLONE_REMOTE_DIR}"
|
||||
color yellow "RCLONE_REMOTE: ${RCLONE_REMOTE}"
|
||||
color yellow "RCLONE_GLOBAL_FLAG: ${RCLONE_GLOBAL_FLAG}"
|
||||
color yellow "ZIP_ENABLE: ${ZIP_ENABLE}"
|
||||
color yellow "ZIP_PASSWORD: ${#ZIP_PASSWORD} Chars"
|
||||
color yellow "ZIP_TYPE: ${ZIP_TYPE}"
|
||||
|
||||
Reference in New Issue
Block a user