Last active
March 3, 2023 09:20
-
-
Save alexberry/92aa1fe9576f084c02590f97c9bcb14e to your computer and use it in GitHub Desktop.
GCP Consistent snapshots for linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As per https://cloud.google.com/compute/docs/disks/creating-linux-application-consistent-pd-snapshots | |
# Append to existing file | |
# /etc/default/instance_configs.cfg | |
[Snapshots] | |
enabled = true | |
timeout_in_seconds = 60 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# As per https://cloud.google.com/compute/docs/disks/creating-linux-application-consistent-pd-snapshots | |
# Tested on RHEL 8.7 with stock packages | |
# /etc/google/snapshots/post.sh | |
for disk in ${1//,/ }; do | |
for disk in $(lsscsi | grep $(echo "$disk" | sed 's|/|:|g') | awk '{print $6}'); do | |
mountpoints=$(mount | grep $disk | awk '{print $3}') | |
for mountpoint in $mountpoints; do | |
echo "mount point is $mountpoint" | |
type=$(findmnt $mountpoint | tail -n -1 | awk '{print $3}') | |
echo "type is $type" | |
# fsfreeze only supports certain filesystems & you should not fsfreeze | |
# your root partition as it can freeze your instance | |
if echo $type | grep -q "ext3\|ext4\|reiserfs\|xfs" && [ $mountpoint != "/" ]; then | |
fsfreeze -u $mountpoint | |
fi | |
done | |
done | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# As per https://cloud.google.com/compute/docs/disks/creating-linux-application-consistent-pd-snapshots | |
# Tested on RHEL 8.7 with stock packages | |
# /etc/google/snapshots/pre.sh | |
for disk in ${1//,/ }; do | |
for disk in $(lsscsi | grep $(echo "$disk" | sed 's|/|:|g') | awk '{print $6}'); do | |
mountpoints=$(mount | grep $disk | awk '{print $3}') | |
for mountpoint in $mountpoints; do | |
echo "mount point is $mountpoint" | |
type=$(findmnt $mountpoint | tail -n -1 | awk '{print $3}') | |
echo "type is $type" | |
# fsfreeze only supports certain filesystems & you should not fsfreeze | |
# your root partition as it can freeze your instance | |
if echo $type | grep -q "ext3\|ext4\|reiserfs\|xfs" && [ $mountpoint != "/" ]; then | |
fsfreeze -f $mountpoint | |
fi | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment