哪吒面板自動備份數據

小知識 · 02-06 · 246 人浏览
哪吒面板自動備份數據

安裝了哪吒面板,想要自動備份數據,數據丟失是很煩的,你懂吧?

原理:當前面板的數據保存本地并不是很妥當,需要一臺VPS B來存儲數據内容。

1.停止面板

systemctl stop nezha-dashboard

2.

cd /home
tar -czvf nezha.tar.gz /opt/nezha

3.通過Sftp傳輸:

sftp username@destination_vps_ip
put /home/nezha.tar.gz /home

4.上傳完畢后別忘了啓動你的面板:

systemctl start nezha-dashboard

當然我們是要做到每日備份,這樣會手動輸入密碼太麻煩了,在當前的哪吒面板VPS生成密鑰上傳到VPS B,這樣就不用每次輸入密碼了。

生成(一路回車即可。):

ssh-keygen -t rsa

上傳:

ssh-copy-id username@destination_vps_ip

測試(如果不需要輸入密碼就連接上去代表成功了。):

ssh username@destination_vps_ip

脚本,例如命名為nezha_data_upload.sh,且文件保存在/home路徑下:

#!/bin/bash

systemctl stop nezha-dashboard
cd /home
tar -czvf nezha.tar.gz /opt/nezha


# 设置远程服务器和文件路径
remote_username="root"
remote_host="destination_vps_ip"
remote_path="/home"
local_file="/home/nezha.tar.gz"

# 连接到 SFTP 并上传文件
sftp $remote_username@$remote_host <<EOF
put $local_file $remote_path
exit
EOF

systemctl start nezha-dashboard

設置定時任務每日0點執行:

chmod +x /home/nezha_data_upload.sh;echo "0 0 * * * /home/nezha_data_upload.sh" | sudo crontab -u root -

查看已經添加到的任務:

crontab -l
本站立足于美利堅合衆國,請讀者自覺遵守當地法律!如有違規,本站不承擔任何法律責任! This site is based in the United States of America, readers are requested to abide by local laws! If there are any violations, this site does not bear any legal responsibility! Theme Jasmine by Kent Liao