Skip to content

Commit ea1879d

Browse files
committed
Patch backuppc to not keep /var/lib/backuppc/LOG open permanently
Because I want to be able to automount /var/lib/backuppc to allow its disks to spin down when not backing up, I need to not keep the one LOG file open that it keeps open. So as to not be too intrusive into the backuppc code and rewrite every LOG caller, I just fork off a loop that open-appends/writes/closes the file on demand. (also backupppc machine needs to know how to turn on the backup backup server, so remember to keep that file in sync with our repo now that we've removed it from CVS control)
1 parent b4b642e commit ea1879d

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
--- BackupPC.debian 2023-01-15 21:24:36.000000000 +1100
2+
+++ BackupPC 2025-05-07 02:12:00.000000000 +1000
3+
@@ -66,7 +66,7 @@
4+
use Carp;
5+
use version;
6+
use Digest::MD5;
7+
-use POSIX qw(setsid);
8+
+use POSIX qw(setsid dup2);
9+
10+
###########################################################################
11+
# Handle command line options
12+
@@ -2011,14 +2011,41 @@
13+
}
14+
}
15+
16+
-#
17+
-# Open the log file and point STDOUT and STDERR there too
18+
+######################################################################
19+
+# Modification fromdebian backuppc 4.4.0-8 20250507 tconnors to not
20+
+# hold the master LOG file open perpetually - only open to append when
21+
+# writing each line
22+
+
23+
+# Open the log file and point STDOUT and STDERR there too - but
24+
+# lazily. We fork a child, and they open the file for append only
25+
+# when there's a line ready to be written.
26+
#
27+
sub LogFileOpen
28+
{
29+
mkpath($LogDir, 0, 0777) if ( !-d $LogDir );
30+
- open(LOG, ">>$LogDir/LOG")
31+
- || die("Can't create LOG file $LogDir/LOG");
32+
+
33+
+ pipe(my $reader, my $writer) or die "pipe failed: $!";
34+
+
35+
+ my $pid = fork();
36+
+ die "fork failed: $!" unless defined $pid;
37+
+
38+
+ if ($pid == 0) {
39+
+ # Child
40+
+ close $writer; # Child reads
41+
+ open(STDIN, "<&", $reader) or die "dup stdin failed: $!";
42+
+ close $reader;
43+
+
44+
+ # Replace this with your custom log processor function
45+
+ run_log_handler();
46+
+
47+
+ exit 0;
48+
+ }
49+
+
50+
+ # Parent
51+
+ close $reader; # Parent writes
52+
+ open(LOG, ">&", $writer) or die "dup log failed: $!";
53+
+ close $writer; # LOG has it now
54+
+
55+
close(STDOUT);
56+
close(STDERR);
57+
open(STDOUT, ">&LOG");
58+
@@ -2028,6 +2055,20 @@
59+
select(STDOUT); $| = 1;
60+
}
61+
62+
+# the log file child handler
63+
+sub run_log_handler {
64+
+ # Example: Just dump everything from STDIN to a file or process it
65+
+ while (<STDIN>) {
66+
+ open(LOG, ">>$LogDir/LOG")
67+
+ || die("Can't create LOG file $LogDir/LOG");
68+
+ print LOG "$_";
69+
+ close(LOG) || die("Can't close LOG file $LogDir/LOG");
70+
+ }
71+
+}
72+
+
73+
+######################################################################
74+
+
75+
+
76+
#
77+
# Initialize the unix-domain and internet-domain sockets that
78+
# we listen to for client connections (from the CGI script and

hosts.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ all:
214214
ZFS_SHARE: "no"
215215
ZFS_UNSHARE: "no"
216216
DO_OVERLAY_MOUNTS: "yes"
217+
custom_files:
218+
- name: /usr/local/bin/turn-on-pve-backup
219+
source: management/turn-on-pve-backup
220+
- name: /usr/local/bin/turn-off-pve-backup
221+
source: management/turn-off-pve-backup
222+
- name: /usr/share/backuppc/bin/BackupPC
223+
source: usr/share/backuppc/bin/BackupPC.patch
217224
iot:
218225
host_is_virtual: true
219226
# host_has_backports: true

roles/install_files/tasks/install_dir_file_or_template.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- name: Include install file
3030
include_tasks: install_file.yml
3131
when: ( source is not regex(".*\\.j2$") ) and
32+
( source is not regex(".*\\.patch") ) and
3233
( source is not regex(".*/$") ) and
3334
( not (
3435
( ( dir_file_or_template.type | default("file")) == "symlink" ) and
@@ -46,3 +47,7 @@
4647
when: ( source is regex(".*\\.j2$") )
4748
# implied can't also be directory
4849

50+
- name: Include install patch
51+
include_tasks: install_patch.yml
52+
when: ( source is regex(".*\\.patch$") )
53+
# implied can't also be directory
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# generates a file .name, from patch .source.patch
3+
4+
- name: "install patch per diff: '{{ dir_file_or_template.name }}' from '{{ source }}'"
5+
patch:
6+
dest: "{{ dir_file_or_template.name | default(('/' ~ dir_file_or_template) | regex_replace('\\.patch$', '')) }}"
7+
src: "{{ source }}"
8+
become: "{{ dir_file_or_template.become | default(true) }}"
9+
notify: "{{ dir_file_or_template.notify | default(omit) }}"

roles/install_user_files/tasks/install_user_dir_file_or_template.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- name: Include install user file
3030
include_tasks: install_user_file.yml
3131
when: ( source is not regex(".*\\.j2$") ) and
32+
( source is not regex(".*\\.patch$") ) and
3233
( source is not regex(".*/$") )
3334
# unlike install_dir_file_or_template, we resolve the symlink locally
3435
# in all cases, because half the time they refer back to something on
@@ -39,3 +40,7 @@
3940
when: ( source is regex(".*\\.j2$") )
4041
# implied can't also be directory
4142

43+
- name: Include install user patch
44+
include_tasks: install_user_patch.yml
45+
when: ( source is regex(".*\\.patch$") )
46+
# implied can't also be directory
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# generates a file .name, from patch .source.patch
3+
4+
- name: "install user patch per diff: ~{{ user }}/'{{ dir_file_or_template.name }}' from '{{ source }}'"
5+
template:
6+
dest: "~{{ user }}/{{ dir_file_or_template.name }}"
7+
src: "{{ source }}"
8+
become: true
9+
become_user: "{{ user }}"

0 commit comments

Comments
 (0)