Git Repository Backup & Protection with Myota bucketZero Storage

Myota bZs supports various backup options, including using the AWS CLI for data backup to Git and restoration.

Backing up a repository

Myota bucketZero storage (bZs) offers various options for backing up a repository, such as serving as a backup destination on Git, utilizing a third-party tool, or employing a command line interface. In this guide, we will demonstrate how to utilize the AWS CLI for backing up and restoring data to Myota bucketZero storage (bZs)..

Pre-requisites

  • Myota credential information
    • Access Key ID
      • Credential to access bZs
    • Secret Access Key
      • Credential to access bZs
    • Bucket Name
      • Bucket name in bZs
    • Endpoint URL
      • URL where bZs is running.
  • Git and Git credentials to fetch/pull/push code

Installing AWS CLI

Linux

  • For Ubuntu
    • $ sudo apt-get update
      $ sudo apt-get install awscli

  • For CentOS
    • $ sudo yum update
      $ sudo yum install awscli

For other Linux distributions please follow instruction at - https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Mac

We recommend you install AWSCLI using Homebrew. (https://brew.sh/)

Windows

Download and run the AWS CLI MSI installer for Windows (64-bit) - https://awscli.amazonaws.com/AWSCLIV2.msi

Configuring Myota Credentials

These steps will guide you through setting up credentials using Named profiles. For more advanced configurations, you can refer to https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html.

Step 1. Create the “credentials” file

Create a credential file at ~/.aws/credentials (Linux & Mac) or %USERPROFILE%\.aws\credentials (Windows)

If the “credentials” file already exists, go to Step 2.

  • ...
    [Myota_BZS]
    aws_access_key_id=YOUR_ACCESS_KEY_ID_FOR_BZS
    aws_secret_access_key=YOUR_SECRET_ACCESS_KEY_FOR_BZS

Step 2. Working with credentials

Put Myota bZs credentials into the “credentials” file.

  • $ AWS_PROFILE=Myota_BZS aws s3 ls s3://…

Step 3. Using named profiles

Now that you have set up Myota bZs, you can easily specify the profile name by using the AWS_PROFILE environment variable.

Backup Git Repository

To upload the entire repository folder, including the .git folder, to Myota bZs, you should begin by cloning and pulling all branches from the remote repository. If you have configured your Myota bZs credentials in the AWS "credentials" file, you can utilize AWS CLI S3 commands for downloading, uploading, listing, and deleting objects. It is important to remember that when executing S3 commands, you must include an additional parameter, specifically the "endpoint-url."

Clone and pull all remote branches

  • $> git clone REPO_URL WORK_DIR
    $> cd WORK_DIR
    $> git branch -r | grep -v '\->' | while read remote; do git branch
    --track "${remote#origin/}" "$remote"; done
    $> git fetch –all
    $> git pull --all

Upload repository to Myota bZs

(note: must be in WORK_DIR)

  • $ AWS_PROFILE=Myota_BZS aws s3 cp . s3://BZS_BUCKET_NAME/REPO_NAME 
    --endpoint-url https://YOUR_BZS_DOMAIN --recursive
Restore repository
  • $ AWS_PROFILE=Myota_BZS aws s3 cp s3://BZS_BUCKET_NAME/REPO_NAME LOCAL_DESTINATION_FOLDER --endpoint-url https://YOUR_BZS_DOMAIN --recursive

Once you have downloaded the repository from bZs, you can push the code to a new repository as part of the recovery process after changing the remote settings. Here is an example of how to change the remote repository URL and push the code to the new repository.

  • $> cd LOCAL_DESTINATION_FOLDER
    $> git remote set-url origin NEW_REPO_URL
    $> git push origin –all

Other Examples to use AWS CLI S3 commands:

Upload a file

  • $ AWS_PROFILE=Myota_BZS aws s3 cp YOUR_SRC_FILE_PATH s3://BZS_BUCKET_NAME/DESTINATION --endpoint-url https://YOUR_BZS_DOMAIN

Upload a folder

  • $ AWS_PROFILE=Myota_BZS aws s3 cp YOUR_SRC_FOLDER_PATH s3://BZS_BUCKET_NAME/DESTINATION --endpoint-url https://YOUR_BZS_DOMAIN 
    --recursive

Download a file

  • $ AWS_PROFILE=Myota_BZS aws s3 cp s3://BZS_BUCKET_NAME/SRC YOUR_DEST_FILE_PATH --endpoint-url https://YOUR_BZS_DOMAIN

Download a folder

  • $ AWS_PROFILE=Myota_BZS aws s3 cp s3://BZS_BUCKET_NAME/SRC YOUR_DEST_FOLDER_PATH --endpoint-url https://YOUR_BZS_DOMAIN --recursive

List files

  • $ AWS_PROFILE=Myota_BZS aws s3 ls s3://BZS_BUCKET_NAME --endpoint-url https://YOUR_BZS_DOMAIN --recursive

Additional commands files

You can also use other low-level commands including

References

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

https://formulae.brew.sh/formula/awscli

https://docs.aws.amazon.com/cli/latest/reference/s3/

https://docs.aws.amazon.com/cli/latest/reference/s3api/