Skip to content

Commit

Permalink
pbackup: Support PBACKUP_DB development
Browse files Browse the repository at this point in the history
Add code to override the sqlite database name via environment variable.
This can help in development, so that code can be tested against a copy
of a real database as an unpriviledged user while avoiding the risk to
block the running server or corrupte the backup data.
  • Loading branch information
donald committed Apr 7, 2025
1 parent 14318b5 commit 81351fa
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bin/pbackup
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,20 @@ sub scan_rsync_log {

our $dbh;

sub get_db_filename {
my $db_filename;
if (exists $ENV{'PBACKUP_DB'}) {
$db_filename = $ENV{'PBACKUP_DB'};
-e $db_filename or die "$db_filename: no such file\n";
} else {
$db_filename = "$ROOT/db/pbackup.db";
}
return $db_filename;
}

sub db_open {
$dbh=DBI->connect("dbi:SQLite:dbname=$ROOT/db/pbackup.db","","",{
my $db_filename = get_db_filename();;
$dbh=DBI->connect("dbi:SQLite:dbname=$db_filename","","",{
AutoCommit=>1,
PrintError=>0,
RaiseError=>1,
Expand Down Expand Up @@ -1791,7 +1803,8 @@ if ($cmd eq 'status') {
} elsif ($cmd eq 'fix_stat') {
cmd_fix_stat();
} elsif ($cmd eq 'sql') {
system('sqlite3','-header',"$ROOT/db/pbackup.db",@ARGV);
my $db_filename = get_db_filename();
system('sqlite3', '-header', $db_filename, @ARGV);
} elsif ($cmd eq 'expire') {
cmd_expire();
} elsif ($cmd eq 'kill') {
Expand Down

0 comments on commit 81351fa

Please sign in to comment.