Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 56 lines (45 sloc) 1.78 KB
#!/bin/bash
TMP_DIR=${TMP_DIR-".backup"}
dest=$1
if [ -z $dest ]
then
echo "Usage: backup S3_BUCKET_URI"
echo
echo "Performs synchronization of the current directory with the S3 URI."
echo "Finds all the *.enc files, flattens their paths and runs synchronization on a flat directory."
exit 1
fi
function unlink_backup() {
(find "$TMP_DIR" -name "*.enc" -type f -exec unlink {} \; && \
rm -d "$TMP_DIR" && \
echo "All hard links unlinked and directory '$TMP_DIR' removed.") || \
(echo "Failed to unlink files and remove '$TMP_DIR'. Extra files?" && return 1)
}
function check_exists() {
if [ -d "$TMP_DIR" ]
then
echo "'$TMP_DIR' already exists. Unsuccessful run before?"
read -p "Unlink files and remove the directory '$TMP_DIR'? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
unlink_backup && echo "'$TMP_DIR' removed." && return 0
fi
return 1
fi
}
check_exists || (echo "To run the script you must remove '$TMP_DIR'." && exit 1)
mkdir "$TMP_DIR" || (echo "Failed to create a temporary directory '$TMP_DIR'." && exit 1)
echo "Creating hard links in '$TMP_DIR' for a sync command..."
find . -path "./$TMP_DIR" -prune -or -name "*.enc" -type f -exec sh -c 'ln {} "'$TMP_DIR'/$(basename {})"' \; || (echo "Failed to create hard links." && exit 1)
echo "Performing synchronization dry run for '$dest'..."
aws s3 sync --dryrun --storage-class STANDARD_IA "$TMP_DIR/" "$dest" || (echo "Failed to perform dry run." && exit 1)
echo "Dry run is successful."
read -p "Proceed? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Performing synchronization with '$dest'..."
aws s3 sync --storage-class STANDARD_IA "$TMP_DIR/" "$dest" || (echo "Failed to sync with S3." && exit 1)
fi
unlink_backup || (echo "Failed to unlink created hard links." && exit 1)
You can’t perform that action at this time.