发送邮件可以参考定时备份MySQL
这篇文章
安装
1 2 3
| apt update && apt-get update \ apt install msmtp -y \ apt install mutt -y
|
Ubuntu 可能还要安装 apt install sendmail
备份脚本
填写配置就好,建议都写绝对路径。不喜欢zip
可以换成tar
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #!/bin/bash
TARGET_PATH=/path/to/bitwarden-data
BACKUP_PATH=/path/to/backup
[email protected]
CURRENT_TIME=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE_SUFFIX=_bitwarden_data.zip
TAR_FILE_NAME=${CURRENT_TIME}${BACKUP_FILE_SUFFIX}
if ! command -v zip &> /dev/null then echo "zip 未安装,请先安装 zip。" exit fi
[ ! -d "$BACKUP_PATH" ] && mkdir -p "$BACKUP_PATH" FILE_GZ=${BACKUP_PATH}/${TAR_FILE_NAME}
zip -q -r $TAR_FILE_NAME $TARGET_PATH
EMAIL_TITLE="Bitwarden_备份_$CURRENT_TIME"
echo "$EMAIL_TITLE" | mutt -s "$TAR_FILE_NAME" $RECV_EMAIL -a $FILE_GZ
cd $BACKUP_PATH find $BACKUP_PATH -mtime +7 -name "*${BACKUP_FILE_SUFFIX}" -exec rm -f {} \;
|
定时任务
每天10:00执行一次
1 2
| crontab -e 0 10 * * * bash /path/to/backup.sh
|