Creating snapshots for backup
Often we will need to create snapshots of instances. These can be used as backup or to create more instances to scale up . Typically, a daily or weekly cron of the Ansible task would help in maintaining a periodic backup.
How to do it…
We can use the gce_snapshot
module to create a snapshot:
- name: create snapshot of instance gce_snapshot: instance_name: app snapshot_name: app-snapshot state: present service_account_email: "{{ service_account_email }}" project_id: "{{ project_id }}" credentials_file: "{{ credentials_file }}" tags: - recipe4
How it works...
In this case, we just need to specify the instance name and the snapshot name. When running this as a cron, we can set the snapshot name to the current date to maintain periodic backup. One thing to note here is that snapshots are incremental. So they consume very little space and thus, save significant cost on storage.