Created
February 18, 2020 02:01
-
-
Save ipha/19875982442c44474144f84870b47582 to your computer and use it in GitHub Desktop.
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 | |
blue='\e[0;34m' | |
red='\e[0;31m' | |
NC='\e[0m' | |
BTRFS_ROOT="/mnt/btrfs" | |
NUM_TO_KEEP=7 | |
new_name=$(date +root_%Y-%m-%d_%T) | |
echo -e "${blue}Taking rw 'last' snapshot of root:${NC}" | |
btrfs subvolume snapshot ${BTRFS_ROOT}/root ${BTRFS_ROOT}/root-last-new | |
btrfs subvolume delete ${BTRFS_ROOT}/root-last | |
mv ${BTRFS_ROOT}/root-last-new ${BTRFS_ROOT}/root-last | |
cp /boot/vmlinuz-linux /boot/vmlinuz-linux-last | |
cp /boot/initramfs-linux-fallback.img /boot/initramfs-linux-last-fallback.img | |
sed -i 's|subvol=root|subvol=root-last|' ${BTRFS_ROOT}/root-last/etc/fstab | |
echo -e "${blue}Taking ro snapshot of root: ${new_name}${NC}" | |
btrfs subvolume snapshot -r ${BTRFS_ROOT}/root ${BTRFS_ROOT}/${new_name} | |
echo -e "${blue}Removing old snapshots${NC}" | |
for snapshot in $(ls ${BTRFS_ROOT} | grep root_ | sort | head -n -"${NUM_TO_KEEP}"); do | |
echo -e "Removing ${snapshot}" | |
btrfs subvolume delete ${BTRFS_ROOT}/${snapshot} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment