Compare commits
2 commits
f54b2e7961
...
cbca198ef4
Author | SHA1 | Date | |
---|---|---|---|
cbca198ef4 | |||
ac1720f700 |
1 changed files with 51 additions and 0 deletions
51
ShellScripts/rsync-incremental-backups.sh
Normal file
51
ShellScripts/rsync-incremental-backups.sh
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script for performing incremental backups using rsync.
|
||||||
|
|
||||||
|
# Set the script to exit if any command returns a non-zero status.
|
||||||
|
set -o errexit
|
||||||
|
# Set the script to treat unset variables as errors.
|
||||||
|
set -o nounset
|
||||||
|
# Set the script to exit if a pipeline returns a non-zero status.
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Define the source directory you want to back up.
|
||||||
|
readonly SOURCE_DIR="<input folder>"
|
||||||
|
|
||||||
|
# Define the directory where the backups will be stored.
|
||||||
|
readonly BACKUP_DIR="<output folder>"
|
||||||
|
|
||||||
|
# Get the current date and time in the format 'YYYY-MM-DD_HH:MM:SS'.
|
||||||
|
readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
|
||||||
|
|
||||||
|
# Create a path for the current backup using the datetime.
|
||||||
|
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
|
||||||
|
|
||||||
|
# Create a symbolic link called 'latest' that points to the most recent backup.
|
||||||
|
readonly LATEST_LINK="${BACKUP_DIR}/latest"
|
||||||
|
|
||||||
|
# Ensure that the backup directory exists.
|
||||||
|
mkdir -p "${BACKUP_DIR}"
|
||||||
|
|
||||||
|
# Use rsync to perform the backup:
|
||||||
|
# - 'ahv' preserves permissions, owner, group, and provides verbose output.
|
||||||
|
# - '--progress' shows progress during transfer.
|
||||||
|
# - '--stats' shows statistics at the end of the backup.
|
||||||
|
# - '--delete' removes files from the backup that are no longer present in the source.
|
||||||
|
# - '--log-file' specifies a log file for recording backup details.
|
||||||
|
# - '--exclude' excludes the '.cache' directory from being backed up.
|
||||||
|
# - '--link-dest' specifies a directory with previous backups, enabling hard-linking of unchanged files.
|
||||||
|
# - "${SOURCE_DIR}/" is the source directory to be backed up.
|
||||||
|
# - "${BACKUP_PATH}" is the destination directory for the current backup.
|
||||||
|
rsync -ahv --progress --stats --delete \
|
||||||
|
--log-file="${BACKUP_DIR}/${DATETIME}.log" \
|
||||||
|
--exclude=".cache" \
|
||||||
|
--link-dest "${LATEST_LINK}" \
|
||||||
|
"${SOURCE_DIR}/" \
|
||||||
|
"${BACKUP_PATH}"
|
||||||
|
|
||||||
|
# Remove the symbolic link 'latest' to the old backup.
|
||||||
|
rm -rfv "${LATEST_LINK}"
|
||||||
|
|
||||||
|
# Create a new symbolic link 'latest' pointing to the most recent backup.
|
||||||
|
ln -s "${BACKUP_PATH}" "${LATEST_LINK}"
|
Loading…
Reference in a new issue