Ossdb-snapshot, Lvm Database Snapshot Tool

Just tossing this out there on the chance it might be useful for others. This script, dubbed ossdb-snapshot, is based on the mysql-snapshot tool from Jeremy Cole. The idea is to simplify management of lvm snapshots for purposes of creating postgresql snapshot style backups (I’ve left the mysql pieces in place in case anyone wants to make it a truely cross-db app), either for backup or pitr setup. Quick example after the jump. In this system, the lvm setup on the master looks something like this:
[root@luigi ~]# lvdisplay --- Logical volume --- LV Name /dev/pipedbvg2/pipedbdata VG Name pipedbvg1 LV Write Access read/write LV Status available LV Size 185.00 GB Current LE 47360 Block device 253:0 --- Logical volume --- LV Name /dev/pipedbvg2xl/pipedbxlog VG Name pipedbvg1xl LV Write Access read/write LV Status available LV Size 27.00 GB Current LE 6912 Block device 253:1
Basically we want to grab a copy of postgresql using the start/stop backup commands, mounting our lvm snapshot at /pipedb/pitr so we can copy it to another box. The commands look something like this:
[root@luigi ~]# ./ossdb-snapshot --dbtype pgsql -u postgres -p password -c --origin-lv pipedbdata --origin-vg pipedbvg2 --snapshot-name pgpitr --snapshot-size 20GB --mountpoint /pipedb/pitr [root@luigi ~]# lvdisplay --- Logical volume --- LV Name /dev/pipedbvg2/pipedbdata VG Name pipedbvg2 LV Write Access read/write LV snapshot status source of /dev/pipedbvg2/pgpitr [active] LV Status available LV Size 185.00 GB Current LE 47360 Block device 253:0 --- Logical volume --- LV Name /dev/pipedbvg2/pgpitr VG Name pipedbvg2 LV Write Access read/write LV snapshot status active destination for /dev/pipedbvg2/pipedbdata LV Status available LV Size 185.00 GB Current LE 47360 COW-table size 20.00 GB COW-table LE 5120 Allocated to snapshot 0.00% Snapshot chunk size 8.00 KB Block device 253:2 --- Logical volume --- LV Name /dev/pipedbvg2xl/pipedbxlog VG Name pipedbvg2xl LV Write Access read/write LV Status available LV Size 27.00 GB Current LE 6912 Block device 253:1 [root@luigi pitr]# rsync -a --progress --delete --exclude='postmaster.pid' --exclude='postgresql.conf' --perms /pipedb/pitr/ mario:/pipedb/data/ [root@luigi ~]# ./ossdb-snapshot -d --origin-vg pipedbvg2 --snapshot-name pgpitr
The above works fine in my setup for doing pitr setups, if you have a different setup or need, you might need to adjust things accordingly.

Copyright © 2021 - xzilla - Powered by Octopress