用于备份我的“home”文件夹的 Bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24003311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash Script to backup my "home" folder
提问by Kevin
How can I skip backing up my "Downloads" folder?
如何跳过备份我的“下载”文件夹?
here's my code:
这是我的代码:
#!/bin/bash
# Daily backup script
# Create some needed variable
day=$(date +%F)
Folder="/home/ME/"
File="/media/MediaTwo/Copy/UbuntuBackup/$day.tar.gz"
# Backup Server Configuration
tar cpzf $File $Folder
# Remove backup files older than 90 days
find $File* -mtime +90 -exec rm {} \;
回答by R Sahu
tar cpzf $File --exclude=Downloads $Folder
回答by BillyBBone
The easiest way to exclude your Downloads folder is to add an option (i.e. --exclude
) to the tar
command.
排除下载文件夹的最简单方法是向命令添加一个选项(即--exclude
)tar
。
I would suggest modifying line 12 of your code to read:
我建议将代码的第 12 行修改为:
tar cpzf $File --exclude "${Folder}Downloads" $Folder
tar cpzf $File --exclude "${Folder}Downloads" $Folder
I think this should do what you're looking for.
我认为这应该可以满足您的要求。
回答by konsolebox
Use extended pattern matching:
使用扩展模式匹配:
shopt -s extglob; shopt -s dotglob
tar cpzf "$File" "$Folder"/!(Downloads)
回答by manuc66
I sugest this one for maximum speed on multi core machines :
我建议在多核机器上获得最大速度:
tar -c --use-compress-program=pigz -f $File --exclude=Downloads $Folder