Merge pull request #25 from ttionya/feature/sends
support backup sends directory
This commit is contained in:
@@ -18,6 +18,7 @@ This tool supports backing up the following files or directories.
|
||||
- `db.sqlite3`
|
||||
- `config.json`
|
||||
- `attachments` (directory)
|
||||
- `sends` (directory)
|
||||
|
||||
|
||||
|
||||
@@ -131,6 +132,10 @@ If you didn't set the `ZIP_ENABLE` environment variable to `TRUE` when you backe
|
||||
|
||||
If you didn't set the `ZIP_ENABLE` environment variable to `TRUE` when you backed up the file, you need to use this option to specify the `attachments.tar` file.
|
||||
|
||||
##### --sends-file
|
||||
|
||||
If you didn't set the `ZIP_ENABLE` environment variable to `TRUE` when you backed up the file, you need to use this option to specify the `sends.tar` file.
|
||||
|
||||
##### --zip-file
|
||||
|
||||
If you set the `ZIP_ENABLE` environment variable to `TRUE` when you backed up the file, you need to use this option to specify the `backup.zip` file.
|
||||
@@ -278,6 +283,12 @@ Set the attachment folder path, you don't need to modify it.
|
||||
|
||||
Default: `${DATA_DIR}/attachments`
|
||||
|
||||
#### DATA_SENDS
|
||||
|
||||
Set the sends folder path, you don't need to modify it.
|
||||
|
||||
Default: `${DATA_DIR}/sends`
|
||||
|
||||
|
||||
|
||||
## Use `.env` file
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
- `db.sqlite3`
|
||||
- `config.json`
|
||||
- `attachments` (directory)
|
||||
- `sends` (directory)
|
||||
|
||||
|
||||
|
||||
@@ -133,6 +134,10 @@ docker run --rm -it \
|
||||
|
||||
如果你在备份文件时没有将 `ZIP_ENABLE` 环境变量设置为 `TRUE`,那你需要用这个选项来指定 `attachments.tar` 文件。
|
||||
|
||||
##### --sends-file
|
||||
|
||||
如果你在备份文件时没有将 `ZIP_ENABLE` 环境变量设置为 `TRUE`,那你需要用这个选项来指定 `sends.tar` 文件。
|
||||
|
||||
##### --zip-file
|
||||
|
||||
如果你在备份文件时将 `ZIP_ENABLE` 环境变量设置为 `TRUE`,则需要使用这个选项来指定 `backup.zip` 文件。
|
||||
@@ -279,6 +284,12 @@ Rclone 远程名称,你可以自己修改命名。
|
||||
|
||||
默认值:`${DATA_DIR}/attachments`
|
||||
|
||||
#### DATA_SENDS
|
||||
|
||||
指定 sends 文件夹路径,你不需要修改它。
|
||||
|
||||
默认值:`${DATA_DIR}/sends`
|
||||
|
||||
|
||||
|
||||
## Use `.env` file
|
||||
|
||||
@@ -14,6 +14,8 @@ function backup_init() {
|
||||
BACKUP_FILE_CONFIG="${BACKUP_DIR}/config.${NOW}.json"
|
||||
# backup bitwarden_rs attachments directory
|
||||
BACKUP_FILE_ATTACHMENTS="${BACKUP_DIR}/attachments.${NOW}.tar"
|
||||
# backup bitwarden_rs sends directory
|
||||
BACKUP_FILE_SENDS="${BACKUP_DIR}/sends.${NOW}.tar"
|
||||
# backup zip file
|
||||
BACKUP_FILE_ZIP="${BACKUP_DIR}/backup.${NOW}.${ZIP_TYPE}"
|
||||
}
|
||||
@@ -52,12 +54,27 @@ function backup_attachments() {
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_sends() {
|
||||
color blue "backup bitwarden_rs sends"
|
||||
|
||||
if [[ -d "${DATA_SENDS}" ]]; then
|
||||
tar -c -C "${DATA_SENDS_DIRNAME}" -f "${BACKUP_FILE_SENDS}" "${DATA_SENDS_BASENAME}"
|
||||
|
||||
color blue "display sends tar file list"
|
||||
|
||||
tar -tf "${BACKUP_FILE_SENDS}"
|
||||
else
|
||||
color yellow "not found bitwarden_rs sends directory, skipping"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup() {
|
||||
mkdir -p "${BACKUP_DIR}"
|
||||
|
||||
backup_db
|
||||
backup_config
|
||||
backup_attachments
|
||||
backup_sends
|
||||
|
||||
ls -lah "${BACKUP_DIR}"
|
||||
}
|
||||
|
||||
@@ -252,6 +252,7 @@ function init_env() {
|
||||
color yellow "DATA_DB: ${DATA_DB}"
|
||||
color yellow "DATA_CONFIG: ${DATA_CONFIG}"
|
||||
color yellow "DATA_ATTACHMENTS: ${DATA_ATTACHMENTS}"
|
||||
color yellow "DATA_SENDS: ${DATA_SENDS}"
|
||||
color yellow "========================================"
|
||||
color yellow "CRON: ${CRON}"
|
||||
color yellow "RCLONE_REMOTE_NAME: ${RCLONE_REMOTE_NAME}"
|
||||
@@ -290,4 +291,10 @@ function init_env_dir() {
|
||||
DATA_ATTACHMENTS="$(dirname "${DATA_ATTACHMENTS:-"${DATA_DIR}/attachments"}/useless")"
|
||||
DATA_ATTACHMENTS_DIRNAME="$(dirname "${DATA_ATTACHMENTS}")"
|
||||
DATA_ATTACHMENTS_BASENAME="$(basename "${DATA_ATTACHMENTS}")"
|
||||
|
||||
# DATA_SEND
|
||||
get_env DATA_SENDS
|
||||
DATA_SENDS="$(dirname "${DATA_SENDS:-"${DATA_DIR}/sends"}/useless")"
|
||||
DATA_SENDS_DIRNAME="$(dirname "${DATA_SENDS}")"
|
||||
DATA_SENDS_BASENAME="$(basename "${DATA_SENDS}")"
|
||||
}
|
||||
|
||||
+42
-1
@@ -5,6 +5,7 @@
|
||||
RESTORE_FILE_DB=""
|
||||
RESTORE_FILE_CONFIG=""
|
||||
RESTORE_FILE_ATTACHMENTS=""
|
||||
RESTORE_FILE_SENDS=""
|
||||
RESTORE_FILE_ZIP=""
|
||||
RESTORE_FILE_DIR="${RESTORE_DIR}"
|
||||
ZIP_PASSWORD=""
|
||||
@@ -19,6 +20,7 @@ function restore_zip() {
|
||||
local FIND_FILE_DB
|
||||
local FIND_FILE_CONFIG
|
||||
local FIND_FILE_ATTACHMENTS
|
||||
local FIND_FILE_SENDS
|
||||
|
||||
if [[ -n "${ZIP_PASSWORD}" ]]; then
|
||||
7z e -aoa -p"${ZIP_PASSWORD}" -o"${RESTORE_EXTRACT_DIR}" "${RESTORE_FILE_ZIP}"
|
||||
@@ -45,6 +47,10 @@ function restore_zip() {
|
||||
FIND_FILE_ATTACHMENTS="$( basename "$(ls ${RESTORE_EXTRACT_DIR}/attachments.*.tar 2>/dev/null)" )"
|
||||
RESTORE_FILE_ATTACHMENTS="${FIND_FILE_ATTACHMENTS:-}"
|
||||
|
||||
# get restore sends file
|
||||
FIND_FILE_SENDS="$( basename "$(ls ${RESTORE_EXTRACT_DIR}/sends.*.tar 2>/dev/null)" )"
|
||||
RESTORE_FILE_SENDS="${FIND_FILE_SENDS:-}"
|
||||
|
||||
RESTORE_FILE_ZIP=""
|
||||
RESTORE_FILE_DIR="${RESTORE_EXTRACT_DIR}"
|
||||
restore_file
|
||||
@@ -95,6 +101,27 @@ function restore_attachments() {
|
||||
fi
|
||||
}
|
||||
|
||||
function restore_sends() {
|
||||
color blue "restore bitwarden_rs sends"
|
||||
|
||||
# When customizing the sends folder, the root directory of the tar file
|
||||
# is the directory name at the time of packing
|
||||
local RESTORE_FILE_SENDS_DIRNAME=$(tar -tf "${RESTORE_FILE_SENDS}" | head -n 1 | xargs basename)
|
||||
local DATA_SENDS_EXTRACT="${DATA_SENDS}.extract"
|
||||
|
||||
rm -rf "${DATA_SENDS}" "${DATA_SENDS_EXTRACT}"
|
||||
mkdir "${DATA_SENDS_EXTRACT}"
|
||||
tar -x -C "${DATA_SENDS_EXTRACT}" -f "${RESTORE_FILE_SENDS}"
|
||||
mv "${DATA_SENDS_EXTRACT}/${RESTORE_FILE_SENDS_DIRNAME}" "${DATA_SENDS}"
|
||||
rm -rf "${DATA_SENDS_EXTRACT}"
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
color green "restore bitwarden_rs sends successful"
|
||||
else
|
||||
color red "restore bitwarden_rs sends failed"
|
||||
fi
|
||||
}
|
||||
|
||||
function check_restore_file_exist() {
|
||||
if [[ ! -f "${RESTORE_FILE_DIR}/$1" ]]; then
|
||||
color red "$2: cannot access $1: No such file"
|
||||
@@ -130,6 +157,12 @@ function restore_file() {
|
||||
RESTORE_FILE_ATTACHMENTS="${RESTORE_FILE_DIR}/${RESTORE_FILE_ATTACHMENTS}"
|
||||
fi
|
||||
|
||||
if [[ -n "${RESTORE_FILE_SENDS}" ]]; then
|
||||
check_restore_file_exist "${RESTORE_FILE_SENDS}" "--sends-file"
|
||||
|
||||
RESTORE_FILE_SENDS="${RESTORE_FILE_DIR}/${RESTORE_FILE_SENDS}"
|
||||
fi
|
||||
|
||||
if [[ -n "${RESTORE_FILE_DB}" ]]; then
|
||||
restore_db
|
||||
fi
|
||||
@@ -139,11 +172,14 @@ function restore_file() {
|
||||
if [[ -n "${RESTORE_FILE_ATTACHMENTS}" ]]; then
|
||||
restore_attachments
|
||||
fi
|
||||
if [[ -n "${RESTORE_FILE_SENDS}" ]]; then
|
||||
restore_sends
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function check_empty_input() {
|
||||
if [[ -z "${RESTORE_FILE_ZIP}${RESTORE_FILE_DB}${RESTORE_FILE_CONFIG}${RESTORE_FILE_ATTACHMENTS}" ]]; then
|
||||
if [[ -z "${RESTORE_FILE_ZIP}${RESTORE_FILE_DB}${RESTORE_FILE_CONFIG}${RESTORE_FILE_ATTACHMENTS}${RESTORE_FILE_SENDS}" ]]; then
|
||||
color yellow "Empty input"
|
||||
color none ""
|
||||
color none "Find out more at https://github.com/ttionya/BitwardenRS-Backup#restore"
|
||||
@@ -188,6 +224,11 @@ function restore() {
|
||||
RESTORE_FILE_ATTACHMENTS="$(basename "$1")"
|
||||
shift
|
||||
;;
|
||||
--sends-file)
|
||||
shift
|
||||
RESTORE_FILE_SENDS="$(basename "$1")"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
color red "Illegal input"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user