我有一个 bash 脚本,可以将重要文件(例如文档、图标等)备份到第二个驱动器。
每次我的计算机启动时它都会运行。
但偶尔,我必须恢复重做图像。
当发生这种情况时,我的备份脚本会备份旧文件并覆盖第二个驱动器上的新文件。
这就是我正在使用的。
DOCS="/home/andy/Documents" # shell variable
SCRIPTS="/home/andy/bin/"
HOME="/home/andy/"
ICONS="/home/andy/ICONS"
MY_Sounds="/usr/share/sounds/My_Sounds/"
DESKTOP="/home/andy/Desktop/"
THUNAR="/home/andy/.config/Thunar/"
Panel_Layouts="/usr/share/mate-panel/layouts/"
DOCS_Backup="/media/storagedrive/Ubuntu_Mate_18.04//Documents_Backups/"
SCRIPTS_Backup="/media/storagedrive/Ubuntu_Mate_18.04//Script_Backups/"
Backup_Directory="/media/storagedrive/Ubuntu_Mate_18.04/"
#
# Remove the divider before each backup
#
rm $Backup_Directory/________________________
#-----------------------------------------------
# Make log of each time computer boots up
#who -b >> /home/andy/Documents/Bootup_Log.txt
#
amixer -D pulse sset Master 40%
clear
echo "Backing up Hard Drive."
# sleep 5
cd $DOCS
touch /home/andy/Documents/Blank.odt
tar -cvzf Ubuntu_Documents.tar.gz *.txt *.doc *.rtf *.html *.png *.pdf *.odt *.ods *.odg *.csv *.xls *.jpg
## ONLY copy file if it's newer than destination file
##
cp Ubuntu_Documents.tar.gz $Backup_Directory
#-----------------------------------------------
cd $SCRIPTS
touch empty_blank.sh
zip -u Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
cp Ubuntu_Scripts.zip -f $Backup_Directory
# Backup bookmarks file
cd /home/andy/.mozilla/seamonkey/mguw3ujw.default/
cp -f bookmarks.html $Backup_Directory
cp -f bookmarks.html /media/storagedrive/Ubuntu_Mate_18.04/Seamonkey_Bookmarks/
cp -f bookmarks.html $DOCS
#-------------------------------------------------------------------------------------------------------------
# Backup sounds
cd $MY_Sounds
zip -u My_Sounds.zip *.mp3 *.wav
rsync -av --update My_Sounds.zip $Backup_Directory
#-------------------------------------------------------------------------------------------------------------
# Backup icons
cd $ICONS
zip -u Ubuntu_Icons.zip *.png *.pnm *.jpg
rsync -av --update Ubuntu_Icons.zip $Backup_Directory
# Backup aliases
cd $HOME
zip -u .bash_aliases.zip .bash_aliases
rsync -av --update .bash_aliases.zip $Backup_Directory
cd $HOME
zip -u bashrc.zip .bashrc
rsync -av --update bashrc.zip $Backup_Directory
#-------------------------------------------------------------------------------------------------------------
# Backup Thunar settings
cd $THUNAR
zip -u Thunar_Settings.zip uca.xml
rsync -av --update Thunar_Settings.zip $Backup_Directory
# Backup fstab
cat /etc/fstab > /home/andy/Downloads/fstab
cd /home/andy/Downloads
zip fstab.zip fstab
mv fstab.zip $Backup_Directory
rm fstab
#---------------------------------------------------------
# Make Redo images owned by me
cd /media/andy/MAXTOR_SDB2/
sudo chown -R andy: /media/andy/MAXTOR_SDB2/
sudo chown -R andy: /usr/share/backgrounds/My_Backgrounds/
#
cd /home/andy/.mozilla/seamonkey/mguw3ujw.default/chrome/
zip -u UserChrome.zip userChrome.css
rsync -av --update UserChrome.zip $Backup_Directory
#
cd $Backup_Directory
echo Just a file that makes a marker. New files are above it. > ________________________
#
cd /home/andy/.mozilla/seamonkey/mguw3ujw.default/reminderfox
cp reminderfox.ics -f $Backup_Directory
#
# Copy mp3s to SDB1 incase UM crashes, so I do not lose everything. :-)
cp /home/andy/Mp3sFor_Car_CD/*.mp3 /media/storagedrive/Ubuntu_Mate_18.04/SongsForCar/
有解决方法吗?
答案1
我通过确保目标文件较新且旧文件没有覆盖它来测试这一点。
DOCS="/home/andy/Documents" # shell variable
Backup_Directory="/media/storagedrive/Ubuntu_Mate_18.04/"
# Copy files ONLY if they are newer
#
cd $DOCS
rsync --progress -r -u Ubuntu_Documents.tar.gz $Backup_Directory