Last active
September 1, 2023 05:10
-
-
Save qzydustin/413c8a4365054fd4915df29210c9023b to your computer and use it in GitHub Desktop.
Backup GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the value of USER_NAME variable to your username | |
export USERNAME="Your username" | |
# Set the value of ACCESS_TOKEN variable to your access token | |
export ACCESS_TOKEN="Your access token" | |
# Get the script directory | |
script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
# Set the backup directory name with the current date | |
backup_directory="backup/$(date +'%Y-%m-%d')" | |
# Check if the github-backup package is installed | |
if pip3 show github-backup > /dev/null 2>&1; then | |
echo "Updating github-backup..." | |
pip3 install --upgrade github-backup | |
else | |
echo "Installing github-backup..." | |
pip3 install github-backup | |
fi | |
# Run the github-backup command | |
echo "Running github-backup..." | |
github-backup $USERNAME --token $ACCESS_TOKEN --output-directory "$script_directory/$backup_directory" --repositories --private --starred --gist | |
# Create a tar archive of the backup directory | |
echo "Creating backup archive..." | |
tar -czvf "$script_directory/$backup_directory.tar.gz" -C "$script_directory" "$backup_directory" | |
# Remove the backup directory | |
echo "Deleting backup directory..." | |
rm -rf "$script_directory/$backup_directory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment