使用 Dropbox 备份 TTRSS

前阵子误操作 docker-compose,玩坏了 TTRSS,订阅全无。经历了血的教训后,我觉得有必要对 TTRSS 进行备份。

Dropbox 配置

使用 root 身份登入服务器,下载 Dropbox 脚本:

1
cd /root && wget https://raw.github.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh

赋可执行权限、运行脚本进行配置:

1
chmod +x dropbox_uploader.sh && ./dropbox_uploader.sh

之后根据输出进行配置,我的输出大致如下:

# output: 
This is the first time you run this script, please follow the instructions:

(note: Dropropbox will change there API from 30.9.2021.
When using dropbox_uploader.sh configured in the past with the old API, have a look at README.md, before continue.)

 1) Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
 2) Click on "Create App", then select "Choose an API: Scoped Access"
 3) "Choose the type of access you need: App folder"
 4) Enter the "App Name" that you prefer (e.g. MyUploader13057149876349), must be uniqe

 Now, click on the "Create App" button.

 5) Now the new configuration is opened, switch to tab "permissions" and check "files.metadata.read/write" and "files.content.read/write"
 Now, click on the "Submit" button.

 6) Now to tab "settings" and provide the following information:
 App key: app_key
 App secret: app_secret
  Open the following URL in your Browser and allow suggested permissions: https://www.dropbox.com/oauth2/authorize?client_id=xxx&token_access_type=offline&response_type=code
 Please provide the access code: xxx

 > App key: app_key
 > App secret: 'app_secret
 > Access code: 'access_code'. Looks ok? [y/N]: y
   The configuration has been saved.

检查是否配置成功:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
./dropbox_uploader.sh info

# output:
Dropbox Uploader v1.0

 > Getting info...

Name:           Tao Boli
UID:            dbid:xx
Email:          name@gmail.com
Country:        HK

备份脚本

创建目录和 ttrss_backup.sh 脚本:

1
mkdir /root/scripts && mkdir /root/dropbox && vim /root/scripts/ttrss_backup.sh

内容填写如下:

 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
#!/bin/bash

SCRIPT_DIR="/root"
NOW=$(date +"%Y%m%d")
TMP_PATH='/tmp'
DOCKER_NAME='postgres'
TTRSS_DB="$TMP_PATH/ttrss.sql"
BAK_FILE_NAME="vps-$NOW.tar.gz"
BAK_FILE="$TMP_PATH/$BAK_FILE_NAME"
DROPBOX_DIR="/root/dropbox"

docker exec "$DOCKER_NAME" pg_dumpall -c -U postgres > "$TTRSS_DB"
echo "数据库备份完成,打包网站数据中..."
tar cfzP "$BAK_FILE" "$TTRSS_DB"
echo "所有数据打包完成,准备上传..."
# 用脚本上传到dropbox
"$SCRIPT_DIR"/dropbox_uploader.sh upload "$BAK_FILE" "$DROPBOX_DIR/$BAK_FILE_NAME"
if [ $? -eq 0 ];then
     echo "上传完成"
else
     echo "上传失败,重新尝试"
fi

# 删除本地的临时文件
rm -f "$TTRSS_DB" "$BAK_FILE"

我在脚本用的是 pg_dumpall 【导出全部】,如果只需要备份 ttrss 的数据库,建议换成 pg_dump <db_name>

赋予可执行权限、并验证一下脚本:

1
chmod +x ttrss_backup.sh && /root/scripts/ttrss_backup.sh

输出如下:

数据库备份完成,打包网站数据中...
所有数据打包完成,准备上传...
 > Uploading "/tmp/vps-20201213.tar.gz" to "/root/dropbox/vps-20201213.tar.gz"... DONE
上传完成

VPS 的上传带宽是真的很行 😋

到 Dropbox 客户端检查下文件是否上传成功:

验证脚本无问题后,进入下一步编写定时任务。

Crontab 定时任务

如果跟我一样不熟悉 cron,推荐下这个网站:crontab.guru - the cron schedule expression editor

我个人定时是每周日和周三上午三点:0 3 * * 0,3

打开 crontab 编辑器:

1
crontab -e

添加内容如下:

1
0 3 * * 0,3 /bin/bash /root/scripts/ttrss_backup.sh > /dev/null

最后 reload crontab:

1
2
3
4
5
service cron reload

# output:
* Reloading configuration files for periodic command scheduler cron                     [ OK ]

参考

updatedupdated2021-02-012021-02-01
加载评论