Configure GCP Compute Engine auto snapshot and auto snapshot delete
Google cloud platform are good enough for all the developers and system admin to create a virtual machines very fast and reliable.
but there is nothing can make it auto snapshot for the instances and auto delete the instances snapshot.
we found out from github, someone has create the shell scripts to do this automatically.
Below are the step you have to done in your GCP compute engine for Linux.
Before going to configure the auto snapshot, you have to grant permission from the GCP control panel.
Step:
wget https://raw.githubusercontent.com/jacksegal/google-compute-snapshot/master/gcloud-snapshot.sh chmod +x gcloud-snapshot.sh sudo mkdir -p /opt/google-compute-snapshot sudo mv gcloud-snapshot.sh /opt/google-compute-snapshot/ sudo mkdir /var/log/snap sudo touch /var/log/snap/snapshot.log sudo chgrp adm /var/log/snap/snapshot.log sudo chmod 664 /var/log/snap/snapshot.log vim /etc/logrotate.d/snap
insert below text into the snap file for log rotation.
/var/log/snap/*.log { daily missingok rotate 14 compress notifempty create 664 root adm sharedscripts }
Configure crontab to executes the scripts for daily backup
crontab -e 0 5 * * * root /opt/google-compute-snapshot/gcloud-snapshot.sh -d 1 >> /var/log/cron/snapshot.log 2>&1
By default snapshots will be kept for 7 days, however they can be kept for longer / shorter, by using the the -d flag:
Usage: ./snapshot.sh [-d ]
Options:
-d Number of days to keep snapshots. Snapshots older than this number deleted.
Default if not set: 7 [OPTIONAL]
Leave a Reply
Want to join the discussion?Feel free to contribute!