为了防止意外情况而导致数据丢失,最好的办法就是备份数据,我就因为服务器突然断电导致Rocket.Chat服务器数据库损坏,所以今天出一个备份Rocket.Chat据库的教程。
1.首先通过ssh连接到你的Linux服务器(这里用的Ubuntu 20.04)
2.输入 su
之后输入管理员密码来获取权限
3.输入 sudo service snap.rocketchat-server.rocketchat-server stop
来停止Rocket.Chat服务
4.输入 sudo service snap.rocketchat-server.rocketchat-mongo status | grep Active
返回 Active: active (running) since Thu 2024-01-04 19:44:48 CST; 45min ago
即代表成功(只要显示Running即可)
5.输入 sudo snap run rocketchat-server.backupdb
如果返回
[*] Creating backup file…
[+] A backup of your data can be found at /var/snap/rocketchat-server/common/backup/rocketchat_backup_XXXXXXXX.XXXX.tar.gz
则表示备份成功,路径就在 /var/snap/rocketchat-server/common/backup/rocketchat_backup_XXXXXXXX.XXXX.tar.gz
,SFTP下载即可
6.接着输入 sudo snap start rocketchat-server.rocketchat-server
启动Rocket.Chat Server即可大功告成
还原
- 重复备份操作的步骤1-4
- 将备份tgz/tar.gz文件复制到 /var/snap/rocketchat-server/common/ 目录下
- 输入恢复指令
sudo snap run rocketchat-server.restoredb /var/snap/rocketchat-server/common/rocketchat_backup——XXXXXXXX.XXXX.tar.gz
4.输入“1” Yes
5.出现以下文字代表恢复成功
[*] Extracting backup file...
[*] Restoring data...
[*] Preparing database...
[+] Restore completed! Please restart the snap.rocketchat services to verify.
6.启动 Rocket.Chat 服务验证恢复是否生效。
sudo snap start rocketchat-server.rocketchat-server