Author Topic: Is there any way to make remote backup to google drive ?  (Read 25944 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Is there any way to make remote backup to google drive ?

Offline
***
Re: Is there any way to make remote backup to google drive ?
« Reply #1 on: May 01, 2018, 03:43:05 PM »
Is there any way to make remote backup to google drive ?

According to CWP support, they are releasing the backup module very soon which will support external locations too.

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #2 on: July 08, 2018, 12:20:19 PM »
Or you could use the default back-up and copy the files over using cron.
This is how you could mount google drive:
https://www.2daygeek.com/mount-access-google-drive-on-linux-with-google-drive-ocamlfuse-client/

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #3 on: May 09, 2019, 09:55:48 AM »
This is based on a script I use for another Control Panel.

What this script does is backup everything in "/backup" folder (admin backups), and upload it to google drive in tar.gz format, this script will run after the CWP admin backup script has ran.

To use; get the gdrive binary for your OS (https://github.com/gdrive-org/gdrive#downloads).

Centos 6/7 64bit:
Code: [Select]
wget https://drive.google.com/uc?id=1Ej8VgsW5RgK66Btb9p74tSdHMH3p4UNb&export=download
Centos 6 32-bit
Code: [Select]
wget https://drive.google.com/uc?id=1eo9hMXz0WyuBwRxPM0LrTtQmhTgOLUlg&export=download
Make it executable:
Code: [Select]
chmod +x gdrive
Move it to /usr/sbin
Code: [Select]
mv gdrive /usr/sbin/
Setup:
Code: [Select]
gdrive about
Follow the link and get the verification code by authenticating with the google account for the drive you want access to.

Add the script into /root directory named: GDbackup.sh:
Code: [Select]
nano /root/GDbackup.sh
Copy  and paste the below script into the new file using (CTRL C / CTRL V).

And then save the file:
Code: [Select]
CTRL + X + Y
Script:
Code: [Select]
#!/bin/bash
IFS=$'\n'

# Copy the folder you want to store your file in at Google Drive (eg. https://drive.google.com/.../folders/...).
DRIVEFOLDERID=

# Days in which to delete the old backups from google drive (set 0 to disable).
DELETEDAYS=180


  echo "#############################################"
  echo "   ---Google Drive Backup---          "
  echo "#############################################"
  gdrive about
  echo "#############################################"

  DATE=$(date '+%d-%m-%Y')
  TS=$(date +'%H%M%S')
  tar -czvf /tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz -C / backup > /dev/null
  BAKFILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz

  if [ -e "$BAKFILE" ] ; then
   if [ "$DELETEDAYS" > 0 ]; then
   upTime=$(date --date="$DELETEDAYS days ago" '+%Y-%m-%dT%T')
   gdrive list -q "name contains 'backup.tar.gz' and name contains '$HOSTNAME' and modifiedTime < '$upTime'" >> drive.txt
   filename='drive.txt'
   # Read the list file
   while read -r line
  do
   theId=$(cut -c-2 <<< "$line")
   #basically skip the first line...
   if [ "$theId" != "Id" ]; then
        echo "Deleting old backup file: "
gdrive delete $(cut -c-33 <<< "$line")
   fi
done < $filename
# Remove temp list file
rm -rf drive.txt
fi


  gdrive upload -p "$DRIVEFOLDERID" --delete "$BAKFILE"
  # ensures removal of backup file from /tmp
  rm -rf "$BAKFILE"
 
  echo "Backup to Google Drive is complete..."
  echo "#############################################"
 fi

exit 0


Run this command to activate the automated cron job:
Code: [Select]
echo 'sh /root/GDbackup.sh' >> /etc/cron.daily/cwp
You will see the backup information in the email that CWP sends when the backup cron has ran, you can also run the script manually:
Code: [Select]
sh /root/GDbackup.sh
and enjoy your free space...! Hope this helps others..

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #4 on: July 01, 2019, 09:52:16 PM »
This is based on a script I use for another Control Panel.

What this script does is backup everything in "/backup" folder (admin backups), and upload it to google drive in tar.gz format, this script will run after the CWP admin backup script has ran.

To use; get the gdrive binary for your OS (https://github.com/gdrive-org/gdrive#downloads).

Centos 6/7 64bit:
Code: [Select]
wget https://drive.google.com/uc?id=1Ej8VgsW5RgK66Btb9p74tSdHMH3p4UNb&export=download
Centos 6 32-bit
Code: [Select]
wget https://drive.google.com/uc?id=1eo9hMXz0WyuBwRxPM0LrTtQmhTgOLUlg&export=download
Make it executable:
Code: [Select]
chmod +x gdrive
Move it to /usr/sbin
Code: [Select]
mv gdrive /usr/sbin/
Setup:
Code: [Select]
gdrive about
Follow the link and get the verification code by authenticating with the google account for the drive you want access to.

Add the script into /root directory named: GDbackup.sh:
Code: [Select]
nano /root/GDbackup.sh
Copy  and paste the below script into the new file using (CTRL C / CTRL V).

And then save the file:
Code: [Select]
CTRL + X + Y
Script:
Code: [Select]
#!/bin/bash
IFS=$'\n'

# Copy the folder you want to store your file in at Google Drive (eg. https://drive.google.com/.../folders/...).
DRIVEFOLDERID=

# Days in which to delete the old backups from google drive (set 0 to disable).
DELETEDAYS=180


  echo "#############################################"
  echo "   ---Google Drive Backup---          "
  echo "#############################################"
  gdrive about
  echo "#############################################"

  DATE=$(date '+%d-%m-%Y')
  TS=$(date +'%H%M%S')
  tar -czvf /tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz -C / backup > /dev/null
  BAKFILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz

  if [ -e "$BAKFILE" ] ; then
   if [ "$DELETEDAYS" > 0 ]; then
   upTime=$(date --date="$DELETEDAYS days ago" '+%Y-%m-%dT%T')
   gdrive list -q "name contains 'backup.tar.gz' and name contains '$HOSTNAME' and modifiedTime < '$upTime'" >> drive.txt
   filename='drive.txt'
   # Read the list file
   while read -r line
  do
   theId=$(cut -c-2 <<< "$line")
   #basically skip the first line...
   if [ "$theId" != "Id" ]; then
        echo "Deleting old backup file: "
gdrive delete $(cut -c-33 <<< "$line")
   fi
done < $filename
# Remove temp list file
rm -rf drive.txt
fi


  gdrive upload -p "$DRIVEFOLDERID" --delete "$BAKFILE"
  # ensures removal of backup file from /tmp
  rm -rf "$BAKFILE"
 
  echo "Backup to Google Drive is complete..."
  echo "#############################################"
 fi

exit 0


Run this command to activate the automated cron job:
Code: [Select]
echo 'sh /root/GDbackup.sh' >> /etc/cron.daily/cwp
You will see the backup information in the email that CWP sends when the backup cron has ran, you can also run the script manually:
Code: [Select]
sh /root/GDbackup.sh
and enjoy your free space...! Hope this helps others..


Hello,
Thank you for your nomination.
Here when you try to run the script this error is reported.

Failed to get file: googleapi: Error 400: Invalid field selection appProperties, invalidParameter

with someone else, did the same thing happen?

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #5 on: July 02, 2019, 03:39:43 AM »
Hi,

Currently I do not have en copy of CWPanel installed, although I am running a control panel which is based on above script and should work with CWP aswell.

Did you install the gdrive module?

Code: [Select]
#!/bin/bash
#
# The function uploads the backup directory
# to Google Drive in tar.gz format

# Copy the Drive folder ID where you'll upload your files (the after the https://drive.google.com/.../folders/...).
DRIVEFOLDERID=''

# Days in which to delete the old backups from google drive (set 0 to disable).
DELETEDAYS=30

# PASSWORD FOR ENCRYPTION (leave blank 2 disable)
PASSWORD=''

  echo "================================"
  gdrive about

  DATE=$(date '+%d-%m-%Y')
  TS=$(date +'%H%M%S')

  BAKFILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz
  ENC_FILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz.gpg
  tar -czvf "$BAKFILE" -C / backup > /dev/null

  if [ "$password" != '' ] ; then
    gpg -c --batch --yes --passphrase "$PASSWORD" "$BAKFILE"
  fi
 
  if [ -e "$BAKFILE" ] ; then
   if [ "$DELETEDAYS" > 0 ]; then
   upTime=$(date --date="$DELETEDAYS days ago" '+%Y-%m-%dT%T')
   gdrive list -q "name contains 'backup.tar.gz' and name contains '$HOSTNAME' and modifiedTime < '$upTime'" >> drive.txt
   filename='drive.txt'
   # Read the list file
   while read -r line
  do
   theId=$(cut -c-2 <<< "$line")
   #basically skip the first line...
   if [ "$theId" != "Id" ]; then
        echo "Deleting old backup file: "
gdrive delete $(cut -d ' ' -f1 <<< "$line")
   fi
   done < $filename
   # Remove temp list file
    rm -rf drive.txt
   fi

  if [ "$password" != '' ] ; then
    gdrive upload -p "$DRIVEFOLDERID" --delete "$ENC_FILE"
  else
    gdrive upload -p "$DRIVEFOLDERID" --delete "$BAKFILE"
  fi
 
  # ensures removal of backup file from /tmp
  rm -rf "$BAKFILE"

  if [ "$password" != '' ] ; then
    rm -rf "$ENC_FILE"
  fi
 
  echo "Google Drive backup complete ..."
  echo "--------------------------------"
 fi

exit 0

Daz

Offline
**
Re: Is there any way to make remote backup to google drive ?
« Reply #6 on: July 02, 2019, 11:54:10 AM »
Hi,

Currently I do not have en copy of CWPanel installed, although I am running a control panel which is based on above script and should work with CWP aswell.
Just out of curiosity, which control panel are you now using instead of CWP?

Offline
*****

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #8 on: July 02, 2019, 02:14:31 PM »
I use VestaCP on Ubuntu 18.04, the VestaCP requires more 'manual' setup than CWP, I wouldn't say it's for beginners but it's 100% open source. Personally, I will not run code that I cannot see, hence I moved from CWP.

Offline
**
Re: Is there any way to make remote backup to google drive ?
« Reply #9 on: July 02, 2019, 02:43:30 PM »
I use VestaCP on Ubuntu 18.04, the VestaCP requires more 'manual' setup than CWP, I wouldn't say it's for beginners but it's 100% open source. Personally, I will not run code that I cannot see, hence I moved from CWP.
I've checked it once. I remember it to be pretty simple.
Actually I have another server running ISPConfig for a single site and it's a no hassle control panel. But for my reseller setup, I find CWP to be the best one with most features.

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #10 on: July 03, 2019, 03:01:51 PM »
Hi,

Currently I do not have en copy of CWPanel installed, although I am running a control panel which is based on above script and should work with CWP aswell.

Did you install the gdrive module?

Code: [Select]
#!/bin/bash
#
# The function uploads the backup directory
# to Google Drive in tar.gz format

# Copy the Drive folder ID where you'll upload your files (the after the https://drive.google.com/.../folders/...).
DRIVEFOLDERID=''

# Days in which to delete the old backups from google drive (set 0 to disable).
DELETEDAYS=30

# PASSWORD FOR ENCRYPTION (leave blank 2 disable)
PASSWORD=''

  echo "================================"
  gdrive about

  DATE=$(date '+%d-%m-%Y')
  TS=$(date +'%H%M%S')

  BAKFILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz
  ENC_FILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz.gpg
  tar -czvf "$BAKFILE" -C / backup > /dev/null

  if [ "$password" != '' ] ; then
    gpg -c --batch --yes --passphrase "$PASSWORD" "$BAKFILE"
  fi
 
  if [ -e "$BAKFILE" ] ; then
   if [ "$DELETEDAYS" > 0 ]; then
   upTime=$(date --date="$DELETEDAYS days ago" '+%Y-%m-%dT%T')
   gdrive list -q "name contains 'backup.tar.gz' and name contains '$HOSTNAME' and modifiedTime < '$upTime'" >> drive.txt
   filename='drive.txt'
   # Read the list file
   while read -r line
  do
   theId=$(cut -c-2 <<< "$line")
   #basically skip the first line...
   if [ "$theId" != "Id" ]; then
        echo "Deleting old backup file: "
gdrive delete $(cut -d ' ' -f1 <<< "$line")
   fi
   done < $filename
   # Remove temp list file
    rm -rf drive.txt
   fi

  if [ "$password" != '' ] ; then
    gdrive upload -p "$DRIVEFOLDERID" --delete "$ENC_FILE"
  else
    gdrive upload -p "$DRIVEFOLDERID" --delete "$BAKFILE"
  fi
 
  # ensures removal of backup file from /tmp
  rm -rf "$BAKFILE"

  if [ "$password" != '' ] ; then
    rm -rf "$ENC_FILE"
  fi
 
  echo "Google Drive backup complete ..."
  echo "--------------------------------"
 fi

exit 0

Daz

Hello people.
Thanks for all the help and attention.
I found my error was that I did not fill the field DRIVEFOLDERID =
After filling properly it worked perfect.
Thank you for sharing your scritp.

Offline
*
Re: Is there any way to make remote backup to google drive ?
« Reply #11 on: August 15, 2019, 03:34:30 AM »
This is based on a script I use for another Control Panel.

What this script does is backup everything in "/backup" folder (admin backups), and upload it to google drive in tar.gz format, this script will run after the CWP admin backup script has ran.

To use; get the gdrive binary for your OS (https://github.com/gdrive-org/gdrive#downloads).

Centos 6/7 64bit:
Code: [Select]
wget https://drive.google.com/uc?id=1Ej8VgsW5RgK66Btb9p74tSdHMH3p4UNb&export=download
Centos 6 32-bit
Code: [Select]
wget https://drive.google.com/uc?id=1eo9hMXz0WyuBwRxPM0LrTtQmhTgOLUlg&export=download
Make it executable:
Code: [Select]
chmod +x gdrive
Move it to /usr/sbin
Code: [Select]
mv gdrive /usr/sbin/
Setup:
Code: [Select]
gdrive about
Follow the link and get the verification code by authenticating with the google account for the drive you want access to.

Add the script into /root directory named: GDbackup.sh:
Code: [Select]
nano /root/GDbackup.sh
Copy  and paste the below script into the new file using (CTRL C / CTRL V).

And then save the file:
Code: [Select]
CTRL + X + Y
Script:
Code: [Select]
#!/bin/bash
IFS=$'\n'

# Copy the folder you want to store your file in at Google Drive (eg. https://drive.google.com/.../folders/...).
DRIVEFOLDERID=

# Days in which to delete the old backups from google drive (set 0 to disable).
DELETEDAYS=180


  echo "#############################################"
  echo "   ---Google Drive Backup---          "
  echo "#############################################"
  gdrive about
  echo "#############################################"

  DATE=$(date '+%d-%m-%Y')
  TS=$(date +'%H%M%S')
  tar -czvf /tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz -C / backup > /dev/null
  BAKFILE=/tmp/$HOSTNAME.$DATE.$TS.backup.tar.gz

  if [ -e "$BAKFILE" ] ; then
   if [ "$DELETEDAYS" > 0 ]; then
   upTime=$(date --date="$DELETEDAYS days ago" '+%Y-%m-%dT%T')
   gdrive list -q "name contains 'backup.tar.gz' and name contains '$HOSTNAME' and modifiedTime < '$upTime'" >> drive.txt
   filename='drive.txt'
   # Read the list file
   while read -r line
  do
   theId=$(cut -c-2 <<< "$line")
   #basically skip the first line...
   if [ "$theId" != "Id" ]; then
        echo "Deleting old backup file: "
gdrive delete $(cut -c-33 <<< "$line")
   fi
done < $filename
# Remove temp list file
rm -rf drive.txt
fi


  gdrive upload -p "$DRIVEFOLDERID" --delete "$BAKFILE"
  # ensures removal of backup file from /tmp
  rm -rf "$BAKFILE"
 
  echo "Backup to Google Drive is complete..."
  echo "#############################################"
 fi

exit 0


Run this command to activate the automated cron job:
Code: [Select]
echo 'sh /root/GDbackup.sh' >> /etc/cron.daily/cwp
You will see the backup information in the email that CWP sends when the backup cron has ran, you can also run the script manually:
Code: [Select]
sh /root/GDbackup.sh
and enjoy your free space...! Hope this helps others..

Thanks for this tips.

But I see this not make cron each day.  how to see tach cron? Another thing i see the backup don't take the email account. How to add email account in the backup. 

Thanks