Add: documentation

This commit is contained in:
Aroy-Art 2023-09-08 10:20:11 +02:00
parent ac1720f700
commit cbca198ef4
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -1,20 +1,42 @@
#!/bin/bash #!/bin/bash
# A script to perform incremental backups using rsync # Script for performing incremental backups using rsync.
# Set the script to exit if any command returns a non-zero status.
set -o errexit set -o errexit
# Set the script to treat unset variables as errors.
set -o nounset set -o nounset
# Set the script to exit if a pipeline returns a non-zero status.
set -o pipefail set -o pipefail
#readonly SOURCE_DIR="${HOME}" # Define the source directory you want to back up.
readonly SOURCE_DIR="<input folder>" readonly SOURCE_DIR="<input folder>"
# Define the directory where the backups will be stored.
readonly BACKUP_DIR="<output folder>" 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')" 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}" 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" readonly LATEST_LINK="${BACKUP_DIR}/latest"
# Ensure that the backup directory exists.
mkdir -p "${BACKUP_DIR}" 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 \ rsync -ahv --progress --stats --delete \
--log-file="${BACKUP_DIR}/${DATETIME}.log" \ --log-file="${BACKUP_DIR}/${DATETIME}.log" \
--exclude=".cache" \ --exclude=".cache" \
@ -22,5 +44,8 @@ rsync -ahv --progress --stats --delete \
"${SOURCE_DIR}/" \ "${SOURCE_DIR}/" \
"${BACKUP_PATH}" "${BACKUP_PATH}"
# Remove the symbolic link 'latest' to the old backup.
rm -rfv "${LATEST_LINK}" rm -rfv "${LATEST_LINK}"
# Create a new symbolic link 'latest' pointing to the most recent backup.
ln -s "${BACKUP_PATH}" "${LATEST_LINK}" ln -s "${BACKUP_PATH}" "${LATEST_LINK}"