Scripts/linux/sync.sh
2026-06-19 11:40:49 -05:00

35 lines
766 B
Shell
Executable file

#!/bin/bash
job_name="$1"
src="$2"
dest="$3"
# Validate required params.
if [[ -z "$job_name" || -z "$src" || -z "$dest" ]]; then
echo "Missing required parameter!"
echo " Usage: sync.sh [name] [source] [destination]"
exit 1
fi
# Bail if the lockfile already exists
if [ -f "/tmp/$job_name" ]; then
exit 0
fi
# Bail if the source path doesn't exist
if [ ! -d "$src" ]; then
echo "Source path '$src' does not exist!"
exit 1
fi
# Bail if the destination path doesn't exist
if [ ! -d "$dest" ]; then
echo "Destination path '$dest' does not exist!"
exit 1
fi
# Create the lockfile
touch /tmp/$job_name
# Archive, Partial w/ Progress & Preserve Permissions
rsync -apP "$src" "$dest"
# Remove the lockfile when done
rm /tmp/$job_name