创建一个脚本来备份文件或目录树,方法是制作文件的 zip 并将其复制 $HOME/Backups。zipfile 名称应包括它正在备份的内容以及文件的创建日期。该脚本应采用随机数量的参数来指定要备份的内容。如果没有给它至少一项包含在备份中,它应该抱怨。我已经完成了大部分工作,但我遇到了多个文件的问题,即要同时备份的文件 1 文件 2
#!/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