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.


chmod +x
sudo mkdir -p /opt/google-compute-snapshot
sudo mv /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 {
 rotate 14
 create 664 root adm

Configure crontab to executes the scripts for daily backup

crontab -e

0 5 * * * root /opt/google-compute-snapshot/ -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: ./ [-d ]


   -d  Number of days to keep snapshots. Snapshots older than this number deleted.
       Default if not set: 7 [OPTIONAL]
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *