Skip to content

Instantly share code, notes, and snippets.

@valentineus
Created January 9, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valentineus/7ba3058414ffea9631492c7e63dbe3db to your computer and use it in GitHub Desktop.
Save valentineus/7ba3058414ffea9631492c7e63dbe3db to your computer and use it in GitHub Desktop.
Synchronization of backup copies of repositories with code.
#!/bin/bash
# Author: Valentin Popov
# Email: info@valentineus.link
# Date: 2018-11-13
# Usage: /bin/bash start-sync.sh /path/to/input
# Description: Starting repository synchronization.
# Updating the Environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export PATH="$PATH:/usr/local/scripts"
# Search file sync
if [ "$1" ]; then
SCRIPT="$(readlink --canonicalize-missing "$1")"
if ! [ -f "$SCRIPT" ]; then
exit 0
fi
else
echo "No SCRIPT parameter"
exit 1
fi
# Search source directory
if [ "$2" ]; then
INPUT="$(readlink --canonicalize-missing "$2")"
if ! [ -d "$INPUT" ]; then
exit 0
fi
else
echo "No INPUT parameter"
exit 1
fi
# Run synchronizer
eval "$SCRIPT" "$INPUT"
# End of work
exit 0
#!/bin/bash
# Author: Valentin Popov
# Email: info@valentineus.link
# Date: 2018-11-13
# Usage: /bin/bash sync-repositories.sh /path/to/input
# Description: Update existing users.
# Updating the Environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export PATH="$PATH:/usr/local/scripts"
exec 1> >(logger --stderr --tag "SYNC_REPOSITORIES") 2>&1
echo "Script started"
if [ "$1" ]; then
INPUT="$(readlink --canonicalize-missing "$1")"
if ! [ -d "$INPUT" ]; then
echo "Destination directory does not exist"
exit 1
fi
else
echo "No INPUT parameter"
exit 1
fi
# Processing repositories
find "$INPUT" -maxdepth 2 -mindepth 2 -type d -print | while read DIR; do
echo "In the process: $(basename "$DIR")"
git --git-dir="$DIR" remote update --prune
done
# End of work
echo "Script has been successfully completed"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment