How to backup and restore VPS server to Google Drive Print

  • 0

In order to use this guide, you will need to have an existing Google Drive account. You can sign up for a free Google Drive account at https://www.google.com/drive/. A free Google Drive account will give you 15 GB of storage. You can upgrade to a paid plan for more storage.

Step 1: Install & configure gdrive cli client

To install and configure the gdrive program for your account, follow these steps:

  1. Log in to your VPS using SSH.
  2. At the command prompt, type the following commands to download and extract the gdrive program:
    cd ~
    wget https://github.com/prasmussen/gdrive/releases/download/2.1.1/gdrive_2.1.1_linux_386.tar.gz
    tar xvzf gdrive_2.1.1_linux_386.tar.gz
    
  3. To make the gdrive program accessible from any directory in your account, type the following commands:

    mkdir ~/bin
    mv ~/gdrive ~/bin
  4. To configure gdrive to access your Google Drive account, type the following command:

    gdrive about
  5. The Authentication needed message appears. Copy the URL, and then paste it into your web browser. (Log in to your Google Drive account if necessary.)
  6. Click Allow.

  7. Click the clipboard icon to copy the verification code. At the command prompt, paste the verification code that you obtained in step 7, and then press Enter. You should receive the following message (the actual names and amounts will differ):

    User: Kelly Koe, [email protected]
    Used: 181.6 MB
    Free: 32.1 GB
    Total: 32.2 GB
    Max upload size: 5.2 TB
    

    gdrive is now configured to use your Google Drive account.

  8. To list your Google Drive files and directories, type the following command:

    gdrive list

    This command displays the ID number, name, type, size, and creation date for all of the files and directories in your Google Drive account.

Step 2: Configure backups to Google Drive

  1. To create a directory on Google Drive in which to store your backup files, type the following command. You can replace backups with any name you want to use:
    gdrive mkdir backups
    
  2. To verify that the directory was created successfully, type the following command:

    gdrive list

    Note the ID for the directory, as you will need this information below.

  3. After you verify that the Google Drive directory was created successfully, you are ready to set up a cron job that backs up files to the directory automatically. To do this, the cron command must run the gdrive program with the correct ID of the destination directory.

    For example, the following command demonstrates how to back up the entire public_html directory to the Google Drive backups directory daily at 2:30 AM. You should replace username with your own A2 Hosting account username, and replace ID with the ID of the backups directory:

    30 2 * * * /home/username/bin/gdrive upload --parent ID --recursive /home/username/public_html

    You can also back up individual files. The following cron job shows how to do this with a file named backup.tar.gz:

    30 2 * * * /home/username/bin/gdrive upload --parent ID /home/username/backup.tar.gz

Step 3: How to restore from Google Drive

To restore data from Google Drive to your VoxVM VPS server, follow this step:

  1. Use the gdrive download commands:
    • To restore an individual file, type the following command. Replace ID with the ID of the file you want to restore:
      gdrive download ID
    • To restore an entire directory, type the following command. Replace ID with the ID of the directory you want to restore:

      gdrive download --recursive ID

Was this answer helpful?

« Back