File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 141141 example = literalExpression "./my-custom-site" ;
142142 } ;
143143 } ;
144+
145+ backup = {
146+ enable = mkEnableOption "backup census data after each run" // {
147+ default = false ;
148+ } ;
149+
150+ destination = mkOption {
151+ type = types . str ;
152+ default = "" ;
153+ description = "Backup destination (e.g., 'gemini2.lan:/var/backups/census/')" ;
154+ example = "gemini2.lan:/var/backups/census/" ;
155+ } ;
156+
157+ command = mkOption {
158+ type = types . nullOr types . str ;
159+ default = null ;
160+ description = "Custom backup command. If null, uses scp with timestamped filename." ;
161+ example = literalExpression ''"'' ${pkgs.rsync}/bin/rsync -a census.jsonl '' ${cfg.backup.destination}"'' ;
162+ } ;
163+ } ;
144164 } ;
145165
146166 config = mkIf cfg . enable {
167+ assertions = [
168+ {
169+ assertion = ! cfg . backup . enable || cfg . backup . destination != "" ;
170+ message = "services.bitcoin-node-census.backup.destination must be set when backup.enable is true" ;
171+ }
172+ ] ;
173+
147174 users . users . ${ cfg . user } = {
148175 isSystemUser = true ;
149176 group = cfg . group ;
193220 >> census.jsonl
194221
195222 echo "Census complete!"
223+ '' + optionalString cfg . backup . enable ''
224+ echo "Backing up census data..."
225+ ${ if cfg . backup . command != null then
226+ cfg . backup . command
227+ else
228+ ''
229+ TIMESTAMP=$(${ pkgs . coreutils } /bin/date +%Y-%m-%d)
230+ ${ pkgs . openssh } /bin/scp census.jsonl "${ cfg . backup . destination } census-$TIMESTAMP.jsonl"
231+ echo "Backup complete: census-$TIMESTAMP.jsonl"
232+ ''
233+ }
196234 '' ;
197235 } ;
198236
You can’t perform that action at this time.
0 commit comments