好吧,我使用以下脚本进行备份:
#! /bin/bash
# Gets date of most recent backup.
newestfile=$(cd /home/<USERNAME>/.Backups && find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
budate=`echo $newestfile| cut -c10-19`
# Gets current date
cdate=$(date --iso)
# If the cureent date is the same as the date of the most recent backup, don't run the backup, just give a notification that says it has already been done today.
if [ $cdate = $budate ]; then
echo "Backup Complete"
notify-send -i /home/<USERNAME>/Pictures/Logos/safe.png "Backup Status" "Already started/finished backup for today."
# If the dates are different, start the backup.
else
echo "Starting backup"
notify-send -i /home/<USERNAME>/Pictures/Logos/safe.png "Backup Status" "Starting backup for today."
# Compresses the files into .tar.gz format
tar -cvpzf /home/<USERNAME>/.Backups/backup-$(date +%Y-%m-%d-%H:%M).tar.gz "/home/<USERNAME>/folder/to/back/up" --exclude=.Backups && notify-send --expire-time=60000 -i /home/tim/Pictures/Home/Logos/safe.png 'Backup Status' 'Finished backup for today.'
fi
Run Code Online (Sandbox Code Playgroud)
这将保存一个如下所示的备份文件:
backup-2014-07-26-13:13.tar.gz
Run Code Online (Sandbox Code Playgroud)
在隐藏文件夹中 /home/<USERNAME>/.Backups
用于通知的 safe.png 文件可以从这里下载。
将脚本另存/home/<USERNAME>/Scripts为backup.sh
运行以下命令:
chmod +x 脚本/backup.sh mkdir .Backups 触摸 .Backups/backup-2000-01-01-00:00.tar.gz
然后将命令添加Scripts/./backup.sh到登录应用程序的启动中。即使您一天登录多次,您也只能获得 1 个备份。
或者
您还可以使用 cron 定期运行脚本。使用编辑它crontab -e并将此行添加到末尾:
0 15 * * * bash /path/to/script/backup.sh
Run Code Online (Sandbox Code Playgroud)我的代词是他/他
| 归档时间: |
|
| 查看次数: |
17454 次 |
| 最近记录: |