Coder Social home page Coder Social logo

iuztemur / google-cloud-auto-snapshot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grugnog/google-cloud-auto-snapshot

0.0 1.0 0.0 11 KB

Auto snapshot GCE disks. From:

Home Page: https://gitlab.com/alan8/google-cloud-auto-snapshot

Shell 100.00%

google-cloud-auto-snapshot's Introduction

Automatic Snapshots for Google Compute Engine

This is a background bash script to automatically snapshot all Google Compute Engine disks in a Google cloud project.

Google snapshots are incremental, and don't need to be deleted. If you delete an earlier snapshot the block are automatically migrated to the later snapshot. So deleting snapshots does not save space, but for convenience, rather than an infinitely long list, it is useful to purge earlier snapshots assuming that you would never need granularity. This script will default to 60 days. You can change this behavior with an environment variable of DAYS_RETENTION.

For a more detailed description of what the commands do please visit http://badlywired.com/google-compute-engine-snapshot-automation/

Much of the inspiration for this script came from http://stackoverflow.com/questions/27418427/how-to-create-and-rotate-automatic-snapshot and much of the installation instructions from here https://github.com/jacksegal/google-compute-snapshot

How it works

google-cloud-auto-snapshot.sh will:

  • Determine all Compute Engine Disks in the current project, regardless of
  • Take a snapshot of all disks - snapshots prefixed autogcs-{DISK_NAME-YYYY-MM-DD-sssssssss}
  • The script will then delete all associated snapshots taken by the script that are older than 60 days or the value of the environment variable DAYS_RETENTION.

Prerequisites

Installation

Install the script on any single server ( it will back up ALL disks in a project regardless of the server), the script doesn't even have to run on Google Compute Engine instance, any linux machine will work.

Install Script: Download the latest version of the snapshot script and make it executable, e.g. ``` cd ~ wget https://gitlab.com/alan8/google-cloud-auto-snapshot/raw/master/google-cloud-auto-snapshot.sh chmod +x google-cloud-auto-snapshot.sh sudo mkdir -p /opt/google-cloud-auto-snapshot sudo mv google-cloud-auto-snapshot.sh /opt/google-cloud-auto-snapshot/



**Setup CRON**: You should then setup a cron job in order to schedule a snapshot as often as you like, e.g. for daily cron:

0 5 * * * root /opt/google-cloud-auto-snapshot/google-cloud-auto-snapshot.sh >> /var/log/cron/snapshot.log 2>&1


**Manage CRON Output**: Ideally you should then create a directory for all cron outputs and add it to logrotate:

- Create new directory:

sudo mkdir /var/log/cron

- Create empty file for snapshot log:

sudo touch /var/log/cron/snapshot.log

- Change permissions on file:

sudo chgrp adm /var/log/cron/snapshot.log sudo chmod 664 /var/log/cron/snapshot.log

- Create new entry in logrotate so cron files don't get too big :

sudo nano /etc/logrotate.d/cron

- Add the following text to the above file:

/var/log/cron/*.log { daily missingok rotate 14 compress notifempty create 664 root adm sharedscripts }


**To manually test the script:**

sudo /opt/google-cloud-auto-snapshot/google-cloud-auto-snapshot.sh


## Snapshot Retention

Snapshots are kept for 60 days by default.  You can change this with an environment variable DAYS_RETENTION.

## Limitations, possible future enhancements
* Works for all disks in a project, can't be selective
* Only works for default project for the gcloud environment ( see  gcloud info )
* Only manages snapshots created by the script ( prefixed autogcs- )

google-cloud-auto-snapshot's People

Contributors

alanef avatar grugnog avatar jengo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.