我想要备份以下目录:
/usr
/lib
/etc
/lib64
/boot
/sbin
/bin
有没有简单的办法可以做到这一点?
我需要备份这些目录,以便在需要时可以恢复它们。
我刚刚知道dd
但那似乎是dd
要备份整个磁盘。
答案1
DD 是危险的命令,不推荐使用: https://unix.stackexchange.com/a/141037/165083
您可以使用 rsync 代替它,但我使用类似这样的方法进行备份并将其上传到 AWS s3:
function backup() {
###Path###
pathToContent=${directory}
pathToBackup=/home/backup/$(date +"%Y-%m-%d").${directory}.tar.gz
###Backup###
echo "Creating tar.gz file for ${pathToContent}"
tar -czf ${pathToBackup} ${pathToContent}
echo "Uploading ${pathToBackup} to AWS s3"
aws s3 cp --no-progress ${pathToBackup} s3://<BUCKET>
echo "Removing ${pathToBackup}"
rm ${pathToBackup}
}
cd <directory>
for directory in $(ls -d */ | cut -f1 -d'/');
do
echo "BACKUP FOR $directory starting now."
backup $directory
echo "Backup for ${directory} completed successfuly."
done
请更换<directory>
:)