How to automatically backup a Google Sites site every day
Using a terminal, create a folder to store your backup:
Then download google-sites-backup inside this folder
cd /home/your_user/backup git clone https://github.com/google/gdata-python-client.git git clone https://github.com/famzah/google-sites-backup.git
Perform the first, interactive backup
First execution will require our attention, next ones will be automatic and non interactive.
Run the following commands:
cd /home/your_user/backup google-sites-backup/run.sh gdata-python-client/ google-sites-backup/
Here is a guide on the settings that might help you:
- If your Site is hosted on a Google Apps domain, enter it (e.g. example.com); otherwise leave empty: If you are accessing a Google Sites site that you created using GMail account, then you can leave it in blank. If you are trying to back up a site originally created using an account from a custom domain thanks to Google Apps for Work, please enter the domain without the “http://” part. For instance: “example.org”.
- Site name: The Google Sites site name, including only the substring from your Google Sites URL that indicates the name of the site. For instance, if your Google Sites URL is https://sites.google.com/a/example.org/my-super-cool-website/, then enter my-super-cool-website
- Session file to store the auth token [leave empty to skip]: Please enter “gsites-token”.
The following steps are related with your OAuth settings. Please refer to google-sites-backup guide to complete this part:
You need your own OAuth 2.0 credentials:
- You need your own OAuth 2.0 credentials:
- Create a new project in the Google Developers Console on your account.
- Activate the “Google Sites Data” API in the Google Developers Console. Navigate to “APIs & auth”, then “APIs”. If the API isn’t listed in the Developers Console, then skip this step.
- In the Google Developers Console, navigate to “APIs & auth”, then “Credentials”. Click the button “Add credentials” and choose “OAuth 2.0 client ID”. Choose “other” for “Application type”.
- You can now see and use your client ID and client secret.
Configure the non interactive execution script for google-sites-backup
/home/your_user/backup folder, create a file called
gsb.sh (for “Google Sites Backup”) with these contents:
OAUTH2_ID='something-here.apps.googleusercontent.com' OAUTH2_SECRET='SOMETHING-HERE' WIKI='my-super-cool-website' ROOT_BACKUP_DIR='/home/your-username/backup/files' DOMAIN='example.com' SESSION='/home/your-username/backup/gsites-token' if [ -d "$ROOT_BACKUP_DIR" ]; then mv "$ROOT_BACKUP_DIR" "$ROOT_BACKUP_DIR.$(date +%Y%m%d%H%m)" fi google-sites-backup/run.sh gdata-python-client/ google-sites-backup/ \ --client_id="$OAUTH2_ID" \ --client_secret="$OAUTH2_SECRET" \ --domain="$DOMAIN" \ --site="$WIKI" \ --session_file="$SESSION" \ --backup_dir="$ROOT_BACKUP_DIR"
Please make sure to adapt the variables section (lines 1 to 6) to your particular Google Sites site. These should be the same settings used in the non interactive execution.
Now we will create an alias so when we type
gsb this script we have yous created will run. Edit
~/.bashrc and add the following line:
Last thing to do: create a cron entry so
gsb executes every 24 hours.
To open the cron editor. Add the following line:
0 10 * * * gsb
Make sure to save and exit properly.
You can also change the last line for that one
0 10 * * * gsb || mail -s "Google Sites Backup failed" [email protected] (using your own e-mail address) so you will get a warning in your inbox if the system is unable to perform the backup for some reason.
This will perform a backup of your Google Sites site every day at 10:00 AM. You will find your latest backup at
/home/your-username/backup/files and your previous backups at
/home/your-username/backup/ (each legacy version will have the date and hour of expiry appended to the name of the folder).
You can manually perform a backup at anytime by running
gsb in a terminal.