我正在运行 crontab 来备份一些文件夹,但从那时起,我养成了在晚上关闭计算机的习惯,所以我发现它们没有运行......去想象吧?:-)
因此我的 B 计划是创建一个图标放在我的桌面上,用于执行可执行脚本文件。可能是 backup.sh 之类的东西。这样我就可以在关闭计算机之前手动运行命令。
实现此目的的最佳实践方法是什么?以下是 crontab 命令:
44 4 * * * /usr/bin/rsync -av --delete /var/www/html /media/stan/Seagate\ Expansion\ Drive/backups/
33 3 * * * /usr/bin/rsync -av --delete /home/stan/documents /media/stan/Seagate\ Expansion\ Drive/backups/
02 2 * * * /usr/bin/rsync -av --delete /var/backups /media/stan/Seagate\ Expansion\ Drive/backups/
44 1 * * * mysqldump -u root -ppassword --all-databases | gzip > /media/stan/Seagate\ Expansion\ Drive/backups/mysql/mysqlbak-$(date "+\%Y-\%m-\%d_\%H:\%M:\%S").sql.gz
答案1
创建一些脚本
sudo nano /usr/local/bin/rsync_html
#!/bin/bash /usr/bin/rsync -av --delete /var/www/html /media/stan/Seagate\ Expansion\ Drive/backups/
sudo nano /usr/local/bin/rsync_documents
#!/bin/bash /usr/bin/rsync -av --delete /home/stan/documents /media/stan/Seagate\ Expansion\ Drive/backups/
sudo nano /usr/local/bin/rsync_backups
#!/bin/bash /usr/bin/rsync -av --delete /var/backups /media/stan/Seagate\ Expansion\ Drive/backups/
sudo nano /usr/local/bin/backup_mysql
#!/bin/bash mysqldump -u root -ppassword --all-databases | gzip > /media/stan/Seagate\ Expansion\ Drive/backups/mysql/mysqlbak-$(date "+\%Y-\%m-\%d_\%H:\%M:\%S").sql.gz
使脚本可执行
sudo chmod +x /usr/local/bin/rsync_html
sudo chmod +x /usr/local/bin/rsync_documents
sudo chmod +x /usr/local/bin/rsync_backups
sudo chmod +x /usr/local/bin/backup_mysql
更改你的 crontab
44 4 * * * /usr/local/bin/rsync_html
33 3 * * * /usr/local/bin/rsync_documents
02 2 * * * /usr/local/bin/rsync_backups
44 1 * * * /usr/local/bin/backup_mysql
创建一些桌面文件
nano ~/.local/share/applications/scrip1.desktop
[Desktop Entry] Version=1.0 Type=Application Name=rsync html Exec=/usr/local/bin/rsync_html Icon= Categories= Terminal=false StartupNotify=true
nano ~/.local/share/applications/scrip2.desktop
[Desktop Entry] Version=1.0 Type=Application Name=rsync documents Exec=/usr/local/bin/rsync_documents Icon= Categories= Terminal=false StartupNotify=true
nano ~/.local/share/applications/scrip3.desktop
[Desktop Entry] Version=1.0 Type=Application Name=rsync backup Exec=/usr/local/bin/rsync_backups Icon= Categories= Terminal=false StartupNotify=true
nano ~/.local/share/applications/scrip4.desktop
[Desktop Entry] Version=1.0 Type=Application Name=backup mysql Exec=/usr/local/bin/backup_mysql Icon= Categories= Terminal=false StartupNotify=true