On 10/4/20 4:41 PM, backu...@kosowsky.org wrote:
> better to use the hooks
 that Craig has provided

sure.

here's my initial take -- seems to be working well enough.  so far.  still 
testing ...

for a localhost test with 2 'live data' source types that I want to 'snapshot' 
appropriately before backing up,

        (1) an LVM with fast-flux fs data

                lvs
                        LV                VG      Attr       LSize  Pool Origin 
Data%  Meta%  Move Log Cpy%Sync Convert
                        ...
                        LV_DATA1          VG0     -wi-ao---- 30.00g
                        ...

&

        (2) a live sqlite3 db

                ls -al /srv/db/sqlite/app1.db
                        -rw-r--r-- 1 wwwrun www 528K Oct  4 11:00 
/srv/db/sqlite/app1.db


with a localhost config

        /usr/local/etc/backuppc/pc/localhost.pl

that includes

        $Conf{SshPath} = '/usr/bin/ssh';
        $Conf{RsyncClientPath} = 'sudo /usr/bin/rsync';
        $Conf{RsyncSshArgs} = [
                '-e',
                '$sshPath -l root -i /srv/sec/ssh.backuppc.ed25519',
        ];
        $Conf{RsyncArgsExtra} = [
                '--acls',
                '--xattrs',
        ];
        $Conf{RsyncRestoreArgsExtra} = [
                '--acls',
                '--xattrs',
        ];
        $Conf{RsyncShareName} = [
                '/data/data1',
                '/srv/db/sqlite',
        ];
        $Conf{ClientShareName2Path} = {
                '/data/data1'      => '/mnt/BackupPC/snap_data1',
                '/srv/db/sqlite'   => '/srv/db/sqlite-snap',
        };
        $Conf{DumpPreUserCmd}  = '$sshPath -q -x -l root $host -i 
/srv/sec/ssh.backuppc.ed25519 /usr/local/etc/backuppc/scripts/pre-localhost.sh';
        $Conf{DumpPostUserCmd} = '$sshPath -q -x -l root $host -i 
/srv/sec/ssh.backuppc.ed25519 
/usr/local/etc/backuppc/scripts/post-localhost.sh';

and pre-/post- user scripts,

        /usr/local/etc/backuppc/scripts/pre-localhost.sh

                #!/usr/bin/bash
                SQLITE3="/usr/bin/sqlite3"
                BPCMNT="/mnt/BackupPC"
                LV_SNAP_SZ="2G"
                mk-sqlite3-snap () {
                        _dbDIR=$1
                        _dbFILE=$2
                        _uidgid=$3
                        _dbSNAPDIR="${_dbDIR}-snap"
                        if [[ -d ${_dbSNAPDIR} ]]
                        then
                                rm -rf ${_dbSNAPDIR}
                        fi
                        mkdir -p ${_dbSNAPDIR}
                        ${SQLITE3} ${_dbDIR}/${_dbFILE} "vacuum into 
'${_dbSNAPDIR}/${_dbFILE}';"
                        chown -R ${_uidgid} ${_dbSNAPDIR}
                }
                mk-lvm-snap () {
                        _VG=$1
                        _LV=$2
                        _snapLV=$3
                        if [[ $(findmnt -m /dev/${_VG}/${_snapLV}) ]]
                        then
                                umount --force --quiet ${BPCMNT}/${_snapLV}
                                lvremove --force --quiet /dev/${_VG}/${_snapLV}
                        fi
                        lvcreate -s -L${LV_SNAP_SZ} -n ${_snapLV}  
/dev/${_VG}/${_LV}
                        if [[ -d ${BPCMNT}/${_snapLV} ]]
                        then
                                rm -rf ${BPCMNT}/${_snapLV}
                        fi
                        mkdir -p ${BPCMNT}/${_snapLV}
                        mount /dev/${_VG}/${_snapLV} ${BPCMNT}/${_snapLV}
                }
                mk-sqlite3-snap  "/srv/db/sqlite"  "app1.db"  "wwwrun:www"
                mk-lvm-snap      "VG0"  "LV_DATA1"  "snap_data1"
                exit 0

&

        /usr/local/etc/backuppc/scripts/post-localhost.sh

                #!/usr/bin/bash
                BPCMNT="/mnt/BackupPC"
                rm-sqlite3-snap () {
                        _dbDIR=$1
                        # unused: $2
                        # unused: $3
                        _dbSNAPDIR="${_dbDIR}-snap"
                        if [[ -d ${_dbSNAPDIR} ]]
                        then
                                rm -rf ${_dbSNAPDIR}
                        fi
                }
                rm-lvm-snap () {
                        _VG=$1
                        _LV=$2
                        _snapLV=$3
                        if [[ $(findmnt -m /dev/${_VG}/${_snapLV}) ]]
                        then
                                umount --force --quiet ${BPCMNT}/${_snapLV}
                                lvremove --force --quiet /dev/${_VG}/${_snapLV}
                        fi
                        rm -rf ${BPCMNT}/${_snapLV}
                }
                rm-sqlite3-snap  "/srv/db/sqlite"  "app1"  "wwwrun:www"
                rm-lvm-snap      "VG0"  "LV_DATA1"  "snap_data1"
                exit 0

BackupPC exec correctly 'snaps' the LV & db as needed.

As you mentioned, ssh (and getting the keys/perms right!) makes life a lot 
easier -- and, makes managing security a centralized, server-side affair.

Eventually, getting the per share 'type' & args

        mk-sqlite3-snap  "/srv/db/sqlite"  "app1.db"  "wwwrun:www"
        mk-lvm-snap      "VG0"  "LV_DATA1"  "snap_data1"

_into_ the localhost.pc config would be cleaner.  extending the Pre/Post 
commands into hashes might be an option ...

atm that^ is quick-n-dirty, is certainly _not_ a general solution, and hasn't 
_begun_ the biz of error detection/rollback.
but it's simple & works for my simple, current use case.

i will dig around to find/peruse your inline perl snippets you mention!



_______________________________________________
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    https://github.com/backuppc/backuppc/wiki
Project: https://backuppc.github.io/backuppc/

Reply via email to