How To Back Up Your Git Repository To DigitalOcean Spaces


Relying on a supply rule repository for versioning is a most readily useful training that may back get us up and running when a code change causes our application to crash or to behave erratically. However, in case of a event that is catastrophic a full branch getting inadvertently deleted or losing use of a repository, we ought to leverage extra tragedy data recovery methods.

Backing up our rule repository into an item storage space infrastructure provides united states with an copy that is off-site of information that individuals can recover whenever required. Areas is DigitalOcean’s item storage space solution that provides a destination for users to keep backups of electronic assets, papers, and rule.

Compatible because of the S3 API, Spaces we can make use of tools that are s3 S3cmd to interface with it. S3cmd is a client tool that we can use for uploading, retrieving, and data that are managing item storage space through demand line or through scripting.

In this guide we’ll show just how to backup a Git that is remote repository a DigitalOcean Space using S3cmd. To achieve this goal, we will install and configure Git, install S3cmd, and create scripts to back the Git repository up into our room.


In purchase to work well with areas, you may need a DigitalOcean account. You can register on the signup page if you don’t already have one.

From there, you’ll have to set your DigitalOcean Space up and produce an API key, which you yourself can attain by after our tutorial how exactly to produce a DigitalOcean area and API Key.

Once produced, you’ll have to keep consitently the after factual statements about your room handy:

  • Access Key
  • Secret Key (also referred to as token)

Additionally, you ought to have an Ubuntu 16.04 host put up with a sudo user that is non-root. You may get guidance for establishing this up by third Ubuntu 16.04 initial host setup guide.

Once you’ve got your areas information and host put up, check out the section that is next install Git.

Install Git

In this guide, we’ll be using a Git that is remote repository we’ll clone to our server. Ubuntu has Git installed and ready to use in its default repositories, but this version may be older than the most recent release that is available.

We may use the apt package administration tools to upgrade the neighborhood package index and also to down load and install the newest available form of Git.

  • sudo apt-get upgrade
  • sudo apt-get git that is install

For a far more versatile option to install Git and also to guarantee you can consider installing Git from Source.( that you have the latest release,***********)

We’ll be burning from a Git repository’s Address, so we’ll not want to configure Git inside guide. For help with configuring Git, check this out area on the best way to arranged Git.

Now we’ll proceed to cloning our remote Git repository.

Clone a Remote Git Repository

In purchase to clone our Git repository, we’ll create a script to execute the job. Producing a script we can make use of factors helping make certain that we cannot make mistakes in the demand line.

To compose our executable script, we’ll produce a shell that is new file called because of the text editor nano.

Within this file that is blank let’s compose these script.



git clone --mirror $remoterepo $ clonefilename that is localclonedir

Let’s walk through each component of this script.

The very first line — #!/bin/bash — suggests your script will likely be run by the Bash shell. After that, we define the factors that'll be found in the demand, that will run as we perform the script. These factors define these items of setup:

  • remoterepo has been assigned the Git that is remote repository that we are burning from
  • localclonedir describes the host directory or folder we have called it repos( that we will be cloning the remote repository into, in this case****************)
  • clonefilename describes the filename we'll offer towards regional repository that is cloned in this instance we now have called it demoprojectlocal.git

Each of the factors are then called straight within the demand by the end of this script.

The final type of the script makes use of the Git demand line customer you start with the git demand. After that, our company is asking for to clone a repository with clone, and performing it as a mirror form of the repository because of the --mirror label. Which means the repository that is cloned be a similar because the initial one. The 3 factors that individuals defined above are known as with $.

Whenever you are pleased your script you've got written is accurate, it is possible to leave nano by typing the CTRL + x secrets, when prompted to save lots of the file press y.

At this time we are able to run the shell script because of the command that is following

Once you operate the demand, you’ll output that is receive towards following.


Cloning into bare repository './repos/demoprojectlocal.git'... remote: Counting things: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Getting things: 100percent (3/3), done. Checking connectivity... done.

At this time, in the event that you move into that directory you’ll see the sub-folder with the filename that you provided in the script if you list the items in your current directory, you should see your backup directory there, and. That subdirectory could be the clone of this Git repository.

With our remote Git repository cloned, we are able to now proceed to installing S3cmd, which we are able to used to straight back the repository up into item storage space.

Install S3cmd

The S3cmd device we can connect with the areas environment through the demand line. We’ll install the version that is latest of S3cmd from the general public GitHub repository and proceed with the suggested recommendations for setting up it.

Before setting up S3cmd, we must install Python’s Setuptools, since it can help with this installation (S3cmd is written in Python).

  • sudo apt-get install python-setuptools

Press y to keep.

With this installed, we are able to now download the S3cmd tar.gz file with curl.

  • cd /tmp
  • curl -LO

Note that individuals are getting the file into our tmp directory. This a practice that is common getting files onto our host.

You can verify when there is a more recent form of S3cmd available by going to the Releases web page of this tool’s GitHub repository. You can copy the tar.gz( if you find a newer version,********************) Address and replace it in to the curl demand above.

As soon as the down load has finished, unzip and unpack the file utilizing the tar energy:

  • cd ~
  • tar xf /tmp/s3cmd-*.tar.gz

In the commands above, we changed back again to our house directory then executed the tar demand. We utilized two flags because of the demand, the x suggests that individuals desire to expand from that we want to extract from a tar file and, and the f indicates that the immediately adjacent string will be the full path name of the file. Within the file course of this tar file, we additionally suggest it is within the tmp directory.

Once the file is removed, turn into the directory that is resulting install the program making use of sudo:

  • cd s3cmd-*
  • sudo python install

For the command that is above run, we must make use of sudo. The python demand is a call towards Python interpreter to set up the Python script.

Test the install by asking S3cmd because of its variation information:


s3cmd variation 2.0.1

If the truth is comparable production, S3cmd happens to be effectively set up. Next, we will configure S3cmd to get in touch to the item storage space solution.

Configure S3cmd

S3cmd has an configuration that is interactive that can create the configuration file we need to connect to our object storage server. During the configuration process, you will be asked for your Access Key and key that is secret therefore keep these things easily obtainable.

Let’s begin the setup procedure by typing the command that is following***********)

We are prompted to enter our secrets, so let’s paste them in after which accept US the Default area. It's well worth noting that having the ability to alter the Default area is pertinent the AWS infrastructure your tool that is s3cmd originally created to work with. This is not relevant so we accept the default because DigitalOcean requires fewer pieces of information for configuration.

Enter brand new values or accept defaults in brackets with Enter.
Relate to user manual for detail by detail description of most choices.
Access key and key that is secret your identifiers for Amazon S3. Keep them empty for making use of the env factors.
Secret Key []: b8e1ec97b97bff326955375c5example
Standard Area [US]:

Next, we will enter the DigitalOcean endpoint,

Use "" for S3 Endpoint and never alter it towards target Amazon S3.
S3 Endpoint []:

Because areas supports DNS-based buckets, at prompt that is next'll provide you with the bucket value within the needed structure:

Use "%(bucket)" towards target Amazon S3. "%(bucket)s" and "%(location)s" vars c
a be properly used in the event that target S3 system supports dns based buckets.
DNS-style bucket+hostname:port template for accessing a bucket []: %(bucket)

At this time, we are expected to provide an encryption password. We will enter a password we want to use encryption.( so it will be available in the event***********)

Encryption password is employed to safeguard your files from reading
by unauthorized individuals during transfer to S3
Encryption password: secure_password
Way to GPG system [/usr/bin/gpg]:

We're next prompted to get in touch via HTTPS, but DigitalOcean Spaces cannot help transfer that is unencrypted therefore we will press ENTER to just accept the standard, Yes.

when utilizing HTTPS that is secure protocol interaction with Amazon S3
servers is protected from third party eavesdropping. This process is
slow than ordinary HTTP, and may simply be proxied with Python 2.7 or more recent
Utilize HTTPS protocol [Yes]: 

Since our company isn't making use of an HTTP roxy ip address server, we will keep the following prompt blank and press ENTER.

On some companies all access that is internet proceed through a HTTP proxy.
Decide to try establishing it right here if you fail to directly connect to S3
HTTP server name that is proxy

After the prompt the HTTP roxy ip address server title, the setup script gift suggestions a directory of the values it's going to make use of, followed closely by the chance to test them. Whenever test completes effectively, enter Y to save lots of the settings.

Once you conserve the setup, you are going to get verification of its location.

when you yourself have finished all of the installation actions, it is possible to double-check that your particular setup is proper by operating the command that is following

This demand should output a summary of areas you provided.( that you have available under the credentials***********)


2017-12-15 02:52 s3://demospace

This verifies that individuals have actually effectively linked to our DigitalOcean Spaces. We are able to now proceed to backing our Git repository up into item storage space.

Back Up Git Repository into Object Space

With our tools set up and configured, our company is now planning to produce a script which will zip the repository that is local push it into our DigitalOcean area.

From our house directory, let’s call our script and start it in nano.

  • cd ~
  • nano

We’ll compose our script the following.


tar -zcvf archivedemoproject.tar.gz /repos/demoprojectlocal.git
./s3cmd-2.0.1/s3cmd place archivedemoproject.tar.gz s3://demospace

Earlier inside guide, we’ve utilized tar to unzip s3cmd, our company is now making use of tar to zip the Git repository before giving it to Spaces. Within the tar demand, we specify four flags:

  • z compresses utilizing the gzip technique
  • c produces a fresh file in the place of making use of an one( that is existing****************)
  • v suggests that individuals are now being verbose in regards to the files being contained in the compressed file
  • f names the resulting file because of the title defined next sequence

After the flags, our company is supplying a file title the file that is compressed in this instance archivedemoproject.tar.gz. we're additionally supplying the title of this directory that individuals desire to zip /repos/demoprojectlocal.git.

The script then executes s3cmd placed to deliver archivedemoproject.tar.gz to the location area s3://demospace.

Among the commands you'll commonly make use of with S3cmd, the put demand delivers files to areas. Other commands which may be of good use are the get demand to down load files through the area, as well as the delete demand to delete files. A list can be obtained by you of most commands accepted by S3cmd by performing s3cmd without any choices.

To copy your back-up into the space, execute the script we’ll.

You will dsicover the output that is following***********)


demoprojectlocal.git/ ... demoprojectlocal.git/packed-refs upload: 'archivedemoproject.tar.gz' -> 's3://demobucket/archivedemoproject.tar.gz' [1 of 1] 6866 of 6866 100percent in 0s 89.77 kB/s done

You can make sure that the method worked precisely by operating the command that is following***********)

You’ll start to see the output that is following showing your file is inside room.


2017-12-18 20:31 6866 s3://demospace/archivedemoproject.tar.gz

We are in possession of effectively supported our Git repository into our DigitalOcean area.


To make certain that rule may be quickly restored if required, it is vital to keep backups. The s3cmd client, and shell scripts in this tutorial, we covered how to back up a remote Git repository into a DigitalOcean Space through using Git. This really is just one single approach to lots of feasible situations which you should use areas to simply help along with your tragedy data recovery and information persistence methods.

You can find out about that which we can keep in item storage space by reading the tutorials that are following***********)

Helpful tips toward Building Components in Angular2

Previous article

CPanel Backup restore and configuration tutorial

Next article

You may also like


Leave a reply

Your email address will not be published. Required fields are marked *

More in DigitalOcean