Set up automatic Google Cloud Snapshots
Automatic Google Cloud Snapshots
Made possible by jacksegal/google-compute-snapshot
Prerequesits:
- Set Cloud API scope for Compute Engine to Read/Write (requires VM shutdown)
Install Google Cloud Snapshot
sudo mkdir /opt/google-compute-snapshot
sudo mkdir /opt/google-compute-snapshot/log
cd /opt/google-compute-snapshot/
sudo wget https://raw.githubusercontent.com/jacksegal/google-compute-snapshot/master/gcloud-snapshot.sh
sudo chmod +x gcloud-snapshot.sh
Set up logging
cd /opt/google-compute-snapshot/log
sudo touch snapshot.log
sudo chown pbxadmin:root snapshot.log
sudo chmod 664 snapshot.log
Set up logrotate
sudo nano /etc/logrotate.d/cron
Paste the following into the cron file
/opt/google-compute-snapshot/log/*.log {
daily
missingok
rotate 14
compress
notifempty
create 664 root adm
sharedscripts }
Set up Cron job
sudo crontab -e
Add cron line
10 0 * * * /opt/google-compute-snapshot/gcloud-snapshot.sh >> /opt/google-compute-snapshot/log/snapshot.log 2>&1
To Run manually
sudo /opt/google-compute-snapshot/gcloud-snapshot.sh >> /opt/google-compute-snapshot/log/snapshot.log 2>&1