創建一個腳本來備份文件或目錄樹,方法是創建一個文件的zip文件並將其複製到$ HOME/Backups中。 zipfile名稱應該包括它備份的內容以及文件的創建日期。腳本應該隨機指定要備份的參數。如果在備份中至少沒有包含一個項目,則應該投訴。 Ive得到了大部分工作,但即時通訊有多個文件有問題,即文件1文件2備份在同一時間使用bash腳本同時執行多個備份
#!/bin/bash
clear
echo
echo "Use this script to backup files to your home/backups directory"
echo
ls -la
echo
echo "================================================================"
echo
echo -n "Input file(s)/dir to backup: " ; read filez
while [ "$filez" == "" ] ; do
echo -n "You didnt input a filename, try again: " ; read filez
done
while [ ! -e "$filez" ] ; do
echo -n "No such file/dir, try again: " ; read filez
while [ "$filez" == "" ] ; do
echo -n "You didnt input a filename, try again: " ; read filez
done
done
echo
echo "================================================================"
echo
echo -n "Input name of backup file you wish to create(date automatically included): " ; read filezname
while [ "$filezname" == "" ] ; do
echo -n "You didnt input a filename, try again: " ; read filezname
done
zip -r $HOME/backups/$filezname"_$(date +%F)" $filez
也許嘗試異步運行命令:http://stackoverflow.com/questions/2368137/asynchronous-shell-commands – zero298