sh 我的rsync备份脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 我的rsync备份脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash

if [ "$(whoami)" != "root" ]; then
	echo "You should be root to run backup."
fi

backupSource="/home/elayn/"
backupTarget="/run/media/elayn/Jet Black/Backup/Rsync-LinuxHome/" #the dir where the backup is saved

now=$(date +"%Y-%m-%d-%H%M") # name of this backup
snapshot="$backupTarget/$now" 
cd "$backupTarget"
lastBackup=$(ls | tail -1) # ls prints dirs in alphabetical order, so the last entry should be the most current backup, if it exists
mkdir "$snapshot"

if [ "$lastBackup" == "" ]; then
	echo "No previous backups found, creating master..."
	rsync --archive --acls --xattrs --hard-links --verbose --compress --exclude={"/home/*/.thumbnails/*","/home/*/.cache/mozilla/*","/home/*/.cache/chromium/*","/home/*/.local/share/Trash/*","/home/*/.gvfs"} "$backupSource" "$snapshot" &> "$snapshot/rsync.log"
elif [ "$lastBackup" != "" ]; then
	echo "Using $lastBackup as template..."
	rsync --archive --acls --xattrs --hard-links --verbose --compress --exclude={"/home/*/.thumbnails/*","/home/*/.cache/mozilla/*","/home/*/.cache/chromium/*","/home/*/.local/share/Trash/*","/home/*/.gvfs"} --link-dest "$backupTarget/$lastBackup" "$backupSource" "$snapshot" &> "$snapshot/rsync.log"
fi

tail "$snapshot/rsync.log"

以上是关于sh 我的rsync备份脚本的主要内容,如果未能解决你的问题,请参考以下文章

使用rsync的备份脚本

rsync定时同步备份

rsync定时打包脚本

rsync定时打包脚本

sh rsync备份

sh 通过ssh备份rsync