每次在关机或重新启动之前,upload-dropbox
以图形模式(非登录和交互式 shell)在我的 Debian 9 终端中输入可以将 MariaDB 数据库上传到我的 DropBox。
cat /home/debian9/.bashrc
$dir=$HOME/backup
ss-bwg(){
/usr/bin/nohup /usr/local/bin/sslocal -c /etc/ss-bwg.json &
}
backup(){
USERNAME="xxxx"
PASSWORD="xxxx"
mysqldump -u root -pxyzzy wpdatabase > $dir/wp.sql.bak
}
upload-dropbox(){
backup
ss-bwg
export https_proxy=http://127.0.0.1:8118
sudo service privoxy start
cd $dir
Dropbox-Uploader/dropbox_uploader.sh upload * /
sudo service privoxy stop
unset https_proxy
date >> $dir/dropbox.log
}
我想要一种聪明的方式来自动完成这项工作。
sudo cat /etc/systemd/system/upload.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
After=network-online.target mariadb.service
[Service]
EnvironmentFile=/home/debian9/.bashrc
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/debian9/upload.sh
[Install]
WantedBy=multi-user.target
cat /home/debian9/upload.sh
upload-dropbox
sudo systemctl enable upload
sudo systemctl start upload
sudo reboot
重新启动并检查上传的日志信息。
sudo journalctl -u upload
-- Logs begin at Fri 2018-02-02 10:27:08 HKT, end at Fri 2018-02-02 10:28:45 HKT
Feb 02 10:27:40 hwy systemd[1]: Started Run command at shutdown.
上传服务日志中没有错误信息。我的 DropBox 中
没有上传的文件。wp.sql.bak
如何修复它?
答案1
主要错误:
$dir=$HOME/backup
应该补救:
dir="$HOME/backup"
进一步推荐:
双引号路径,例如:
"$dir/wp.sql.bak"