File: storeBackupReplicationWizard.pl

package info (click to toggle)
storebackup 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,396 kB
  • sloc: perl: 24,988; makefile: 44; sh: 37
file content (802 lines) | stat: -rwxr-xr-x 19,467 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
#! /usr/bin/env perl

#
#   Copyright (C) Dr. Heinz-Josef Claes (2012-2022)
#                 hjclaes@web.de
#   
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#


$main::STOREBACKUPVERSION = undef;

use strict;
use Net::Ping;
use POSIX;


sub libPath
{
    my $file = shift;

    my $dir;

    # Falls Datei selbst ein symlink ist, solange folgen, bis aufgelöst
    if (-f $file)
    {
	while (-l $file)
	{
	    my $link = readlink($file);

	    if (substr($link, 0, 1) ne "/")
	    {
		$file =~ s/[^\/]+$/$link/;
	    }
	    else
	    {
		$file = $link;
	    }
	}

	($dir, $file) = &splitFileDir($file);
	$file = "/$file";
    }
    else
    {
	print STDERR "<$file> does not exist, exiting!\n";
        POSIX::_exit 2;
    }

    $dir .= "/../lib";           # Pfad zu den Bibliotheken
    my $oldDir = `/bin/pwd`;
    chomp $oldDir;
    if (chdir $dir)
    {
	my $absDir = `/bin/pwd`;
	chop $absDir;
	chdir $oldDir;

	return (&splitFileDir("$absDir$file"));
    }
    else
    {
	print STDERR "<$dir> does not exist, exiting\n";
        POSIX::_exit 2;
    }
}
sub splitFileDir
{
    my $name = shift;

    return ('.', $name) unless ($name =~/\//);    # nur einfacher Dateiname

    my ($dir, $file) = $name =~ /^(.*)\/(.*)$/s;
    $dir = '/' if ($dir eq '');                   # gilt, falls z.B. /filename
    return ($dir, $file);
}
my ($req, $prog) = &libPath($0);
unshift @INC, "$req";


require 'splitLine.pl';
require 'checkParam2.pl';
require 'checkObjPar.pl';
require 'prLog.pl';
require 'forkProc.pl';
require 'dateTools.pl';
require 'version.pl';
require 'tail.pl';
require 'fileDir.pl';

my $tmpdir = '/tmp';              # default value
$tmpdir = $ENV{'TMPDIR'} if defined $ENV{'TMPDIR'};


my $commentMasterBackup =
    "The master backup is the backup you specify with option 'sourceDir' of " .
    "storeBackup.pl (or maybe '-s' on the command line).\nIt is the base " .
    "directory for replication(s); this means after replication to the delta " .
    "cache directory you backups will the stored at this place like without " .
    "any replication.";
my $commentBackupCopy =
    "The backup copy is a copy realized via replication from the master " .
    "backup directory. The deltas (new files) compared to the previous " .
    "backup(s) is replicated to the delta cache directory and then to the " .
    "backup copy directory mentioned here.";
my $commentCacheDir =
    "The delta cache directory is the place to temporarily store your " .
    "changes from backup to backup before they will be copied to your " .
    "backup copy (on an external disk)";

=head1 NAME

storeBackupReplicationWizard.pl - creates configuration files for replication

=head1 SYNOPSIS

    storeBackupReplicationWizard.pl [-m masterBackupDir]
          [-c backupCopyDir] [-d deltaCacheDir] [-S series] [-T tmpdir]

=head1 DESCRIPTION

If you do not specify one of the directories, they will be asked interactive.
This "wizard" can be used for simple configurations only. It allows to create
configuration files for *one* replication of multiple series to eg. *one*
external disk.

If the directories specified do not exist, it will ask whether you want to
create them

=head1 OPTIONS

=over 8

=item B<--masterBackupDir>, B<-m>

    top level directory of the master backup

=item B<--backupCopyDir>, B<-c>

    top level directory of the backup copy (eg. external disk)

=item B<--deltaCacheDir>, B<-d>

    top level directory of the delta cache

=item B<--series>, B<-S>

    series to be replicated
    use this parameter multiple times for multiple series

=item B<--tmpdir>, B<-T>

    directory for temporary files, default is </tmp>

=back

=head1 COPYRIGHT

Copyright (c) 2012-2022 by Heinz-Josef Claes (see README).
Published under the GNU General Public License v3 or any later version

=cut

my $binPath = &::absolutePath("$req/../bin");

my $Help = &::getPod2Text($0);

&printVersion(\@ARGV, '-V', '--version');

my $CheckPar =
    CheckParam->new('-list' =>
		    [Option->new('-name' => 'masterBackupDir',
				 '-cl_option' => '-m',
				 '-cl_alias' => '--masterBackupDir',
				 '-param' => 'yes'),
		     Option->new('-name' => 'backupCopyDir',
				 '-cl_option' => '-c',
				 '-cl_alias' => '--backupCopyDir',
				 '-param' => 'yes'),
		     Option->new('-name' => 'deltaCacheDir',
				 '-cl_option' => '-d',
				 '-cl_alias' => '--deltaCacheDir',
				 '-param' => 'yes'),
		     Option->new('-name' => 'series',
				 '-cl_option' => '-S',
				 '-cl_alias' => '--series',
				 '-param' => 'yes',
				 '-multiple' => 'yes'),
		     Option->new('-name' => 'tmpdir',
				 '-cl_option' => '-T',
				 '-cl_alias' => '--tmpdir',
				 '-default' => $tmpdir)
		    ]
    );

$CheckPar->check('-argv' => \@ARGV,
                 '-help' => $Help
                 );

my $prLog;
my ($prLogKind) = ['A:BEGIN',
		   'Z:END',
		   'V:VERSION',
		   'I:INFO',
		   'D:DEBUG',
		   'W:WARNING',
		   'E:ERROR'];
$prLog = printLog->new('-kind' => $prLogKind);


# Auswertung der Parameter
my $masterBackupDir = $CheckPar->getOptWithPar('masterBackupDir');
my $masterBackupDirPreset = 1 if $masterBackupDir;
my $backupCopyDir = $CheckPar->getOptWithPar('backupCopyDir');
my $deltaCacheDir = $CheckPar->getOptWithPar('deltaCacheDir');
my $series = $CheckPar->getOptWithPar('series');
(@$series) = sort (@$series) if $series;
$tmpdir = $CheckPar->getOptWithPar('tmpdir');

#
# check if parameters are set
#
$masterBackupDir = &::checkDir($masterBackupDir, 'master backup directory',
			       $commentMasterBackup, $prLog);
$backupCopyDir = &::checkDir($backupCopyDir, 'backup copy directory',
			     $commentBackupCopy, $prLog);
$deltaCacheDir = &::checkDir($deltaCacheDir, 'delta cache directory',
			     $commentCacheDir, $prLog);

$masterBackupDir = &::absolutePath($masterBackupDir);
$backupCopyDir = &::absolutePath($backupCopyDir);
$deltaCacheDir = &::absolutePath($deltaCacheDir);

my $writtenConfFiles = 0;

(@main::cleanup) = ($prLog, undef);
$SIG{INT} = \&cleanup;
$SIG{TERM} = \&cleanup;

#
# check if backup directories are different
#
$prLog->print('-kind' => 'E',
	      '-str' =>
	      ["same path for master backup dir, backup copy dir and " .
	       "delta cache dir were specified.",
	       "Please enter unique paths for each of them"],
	      '-exit' => 1)
    if ($masterBackupDir eq $backupCopyDir and
	$masterBackupDir eq $deltaCacheDir);
$prLog->print('-kind' => 'E',
	      '-str' =>
	      ["same path for master backup dir and backup copy dir " .
	       "were specified.",
	       "Please enter unique paths for each of them"],
	      '-exit' => 1)
    if ($masterBackupDir eq $backupCopyDir);
$prLog->print('-kind' => 'E',
	      '-str' =>
	      ["same path for master backup dir and delta cache dir " .
	       "were specified.",
	       "Please enter unique paths for each of them"],
	      '-exit' => 1)
    if ($masterBackupDir eq $deltaCacheDir);
$prLog->print('-kind' => 'E',
	      '-str' =>
	      ["same path for backup copy dir and delta cache dir " .
	       "were specified.",
	       "Please enter unique paths for each of them"],
	      '-exit' => 1)
    if ($backupCopyDir eq $deltaCacheDir);

#
# check if there's a backup at $masterBackupDir
#
my (@seriesFound) = ();
{
    # try to read series from master backup
    my $s;
    local *DIR;
    opendir(DIR, $masterBackupDir) or
	$prLog->print('-kind' => 'E',
		      '-str' =>
		      ["cannot opendir <$masterBackupDir>"],
		      '-exit' => 1);
    while ($s = readdir DIR)
    {
	my $entry = "$masterBackupDir/$s";
	next if ($s eq '.' or $s eq '..');
	next if -l $entry and not -d $entry;  # only directories
	next unless -d $entry;

	push @seriesFound, $s;
    }
    closedir(DIR);
    (@seriesFound) = sort (@seriesFound);

    # check for existing backups
    my (@p) = ("$masterBackupDir/*/*/.storeBackupLinks");
    my (@b) = <@p>;

    unless (@b)
    {
	$prLog->print('-kind' => 'W',
		      '-str' =>
		      ["cannot find any existing backup at " .
		       "master backup directory <$masterBackupDir>"]);
	unless ($masterBackupDirPreset)
	{
	    my $answer = undef;
	    do
	    {
		print "\nis this ok?\n",
		"yes / no -> ";
		$answer = <STDIN>;
		chomp $answer;
	    } while ($answer ne 'yes' and $answer ne 'no');
	    exit 1 if $answer eq 'no';
	}
    }
    else   # there is something in the master backup
    {
	unless ($series)
	{

	    my $answer = undef;
	    do
	    {
		print "\nfound series <", join('> <', @seriesFound), ">\n",
		(@seriesFound == 1 ? "replicate it?\n" :"replicate them all?\n"),
		"yes / no -> ";
		$answer = <STDIN>;
		chomp $answer;
	    } while ($answer ne 'yes' and $answer ne 'no');

	    if ($answer eq 'yes')
	    {
		(@$series) = @seriesFound;
	    }
	    else
	    {
		print "\ntype series names separated by blanks\n",
		"(use quotes if there is a blank in a name)\n",
		"-> ";
		my $s = <STDIN>;
		chomp $s;
		$series = &ConfigFile::splitQuotedLine($s, '', 1);
		(@$series) = sort (@$series);
	    }
	}
    }
}

$prLog->print('-kind' => 'I',
	      '-str' => [scalar @$series . " series chosen:",
			 "\t<" . join('> <', @$series) . ">"])
    if ($series);

#
# check if series specified exist
#
{
    my (%seriesFound);
    foreach my $s (@seriesFound)
    {
	$seriesFound{$s} = 1;
    }
    my (@sFound, @sNotFound);
    foreach my $s (@$series)
    {
	if (exists $seriesFound{$s})
	{
	    push @sFound, $s;
	}
	else
	{
	    push @sNotFound, $s;
	}
    }
    if (@$series == 0)
    {
	print "\ntype series names you want to replicate separated by blanks\n",
	"(use quotes if there is a blank in a name)\n",
	"-> ";
	my $s = <STDIN>;
	chomp $s;
	$series = &ConfigFile::splitQuotedLine($s, '', 1);
	(@$series) = sort (@$series);
    }
    elsif (@sNotFound)
    {
	my $answer = undef;
	do
	{
	    print
	    "\nthe following selected series were found at <$masterBackupDir>:\n",
	    "\t<", join('> <', sort @sFound), ">\n",
	    "but the following selected series were *not* found:\n",
	    "\t<", join('> <', sort @sNotFound), ">\n",
	    "continue with the selection, stop, change:\n",
	    "continue / stop / change -> ";
	    $answer = <STDIN>;
	    chomp $answer;
	} while ($answer ne 'continue' and $answer ne 'stop' and
		 $answer ne 'change');
	if ($answer eq 'stop')
	{
	    exit 1;
	}
	elsif ($answer eq 'change')
	{
	    my $answer = undef;
	    do
	    {
		print "\nfound series <", join('> <', @seriesFound), ">\n",
		"replicate them all?\n",
		"yes / no -> ";
		$answer = <STDIN>;
		chomp $answer;
	    } while ($answer ne 'yes' and $answer ne 'no');

	    if ($answer eq 'yes')
	    {
		(@$series) = @seriesFound;
	    }
	    else
	    {
		print
		"\ntype series names you want to replicate separated by blanks\n",
		"(use quotes if there is a blank in a name)\n",
		"-> ";
		my $s = <STDIN>;
		chomp $s;
		$series = &ConfigFile::splitQuotedLine($s, '', 1);
		(@$series) = sort (@$series);
	    }
	}
    }
}

#
# generate configuration files
#
my $tmpDir = &::uniqFileName("$tmpdir/stbuRW-");
mkdir $tmpDir, 0700 or
    $prLog->print('-kind' => 'E',
		  '-str' => ["cannot create temporary directory <$tmpDir>"],
		  '-exit' => 1);

(@main::cleanup) = ($prLog, $tmpDir);

{
    my $f = forkProc->new('-exec' => "$binPath/storeBackupUpdateBackup.pl",
			  '-param' => ['--genBackupBaseTreeConf', $tmpDir],
			  '-outRandom' => "$tmpDir/stbuUpdate-",
			  '-prLog' => $prLog);
    $f->wait();
    my $out = $f->getSTDOUT();
    $prLog->print('-kind' => 'W',
		  '-str' =>
		  ["STDOUT of <$binPath/storeBackupUpdateBackup.pl " .
		   "--genBackupBaseTreeConf>:", @$out])
	if (@$out > 0);
    $out = $f->getSTDERR();
    $prLog->print('-kind' => 'E',
		  '-str' =>
		  ["STDERR of <$binPath/storeBackupUpdateBackup.pl " .
		   "--genBackupBaseTreeConf>:", @$out],
		  '-exit' => 1)
	if (@$out > 0);

    $f = forkProc->new('-exec' => "$binPath/storeBackupUpdateBackup.pl",
		       '-param' => ['--genDeltaCacheConf', $tmpDir],
		       '-outRandom' => "$tmpDir/stbuUpdate-",
		       '-prLog' => $prLog);
    $f->wait();
    $out = $f->getSTDOUT();
    $prLog->print('-kind' => 'W',
		  '-str' =>
		  ["STDOUT of <$binPath/storeBackupUpdateBackup.pl " .
		   "--genDeltaCacheConf>:", @$out])
	if (@$out > 0);
    $out = $f->getSTDERR();
    $prLog->print('-kind' => 'E',
		  '-str' =>
		  ["STDERR of <$binPath/storeBackupUpdateBackup.pl " .
		   "--genDeltaCacheConf>:", @$out],
		  '-exit' => 1)
	if (@$out > 0);
}

#
# copy / create configuration files from $tmpDir to their location
#
# generate master backup configuration file
{
    my $fIn = "$tmpDir/storeBackupBaseTree.conf";
    my $fOut = "$masterBackupDir/storeBackupBaseTree.conf";
    my $writeConfigFile = 1;
    if (-e $fOut)
    {
	my $answer = undef;
	do
	{
	    print "\nConfiguration file for master backup directory\n",
	    "<$masterBackupDir> already exists. How to proceed:\n",
	    "overwrite / continue / stop -> ";
	    $answer = <STDIN>;
	    chomp $answer;
	} while ($answer ne 'overwrite' and $answer ne 'stop' and
		 $answer ne 'continue');
	if ($answer eq 'stop')
	{
	    exit 1;
	}
	elsif ($answer eq 'continue')
	{
	    $writeConfigFile = 0;
	}
    }

    if ($writeConfigFile)
    {
	my $l;
	local *IN, *OUT;
	open(IN, '<', $fIn) or
	    $prLog->print('-kind' => 'E',
		      '-str' => ["cannot open temporary file <$fIn>"],
			  '-exit' => 1);
	open(OUT, '>', $fOut) or
	    $prLog->print('-kind' => 'E',
			  '-str' => ["cannot open file <$fOut>"],
			  '-exit' => 1);
	while ($l = <IN>)
	{
	    chomp $l;
	    if ($l =~ /\A;(backupTreeName)=\s*\Z/)
	    {
		print OUT "$1='Master Backup'\n";
	    }
	    elsif ($l =~ /\A;(backupType)=\s*\Z/)
	    {
		print OUT "$1=master\n";
	    }
	    elsif ($l =~ /\A;(seriesToDistribute)=\s*\Z/)
	    {
		print OUT "$1='", join('\' \'', @$series), "'\n";
	    }
	    elsif ($l =~ /\A;(deltaCache)=\s*\Z/)
	    {
		print OUT "$1=$deltaCacheDir\n";
	    }
	    else
	    {
		print OUT "$l\n";
	    }
	}
	close(IN);
	close(OUT);
	$writtenConfFiles |= 1;
	$prLog->print('-kind' => 'I',
		      '-str' =>
		      ["wrote master backup configuration file " .
		       "<$fOut>"]);
    }
}
# generate backup copy configuration file
{
    my $fIn = "$tmpDir/storeBackupBaseTree.conf";
    my $fOut = "$backupCopyDir/storeBackupBaseTree.conf";
    my $writeConfigFile = 1;
    if (-e $fOut)
    {
	my $answer = undef;
	do
	{
	    print "\nConfiguration file for backup copy directory\n",
	    "<$backupCopyDir> already exists. How to proceed:\n",
	    "overwrite / continue / stop -> ";
	    $answer = <STDIN>;
	    chomp $answer;
	} while ($answer ne 'overwrite' and $answer ne 'stop' and
		 $answer ne 'continue');
	if ($answer eq 'stop')
	{
	    exit 1;
	}
	elsif ($answer eq 'continue')
	{
	    $writeConfigFile = 0;
	}
    }

    if ($writeConfigFile)
    {
	my $l;
	local *IN, *OUT;
	open(IN, '<', $fIn) or
	    $prLog->print('-kind' => 'E',
		      '-str' => ["cannot open temporary file <$fIn>"],
			  '-exit' => 1);
	open(OUT, '>', $fOut) or
	    $prLog->print('-kind' => 'E',
			  '-str' => ["cannot open file <$fOut>"],
			  '-exit' => 1);
	while ($l = <IN>)
	{
	    chomp $l;
	    if ($l =~ /\A;(backupTreeName)=\s*\Z/)
	    {
		print OUT "$1='Backup Copy'\n";
	    }
	    elsif ($l =~ /\A;(backupType)=\s*\Z/)
	    {
		print OUT "$1=copy\n";
	    }
	    elsif ($l =~ /\A;(seriesToDistribute)=\s*\Z/)
	    {
		print OUT "$1='", join('\' \'', @$series), "'\n";
	    }
	    elsif ($l =~ /\A;(deltaCache)=\s*\Z/)
	    {
		print OUT "$1=$deltaCacheDir\n";
	    }
	    else
	    {
		print OUT "$l\n";
	    }
	}
	close(IN);
	close(OUT);
	$writtenConfFiles |= 2;
	$prLog->print('-kind' => 'I',
		      '-str' =>
		      ["wrote backup copy configuration file " .
		       "<$fOut>"]);
    }
}
# generate backup copy configuration file
{
    my $fIn = "$tmpDir/deltaCache.conf";
    my $fOut = "$deltaCacheDir/deltaCache.conf";
    my $writeConfigFile = 1;
    if (-e $fOut)
    {
	my $answer = undef;
	do
	{
	    print "\nConfiguration file for delta cache directory\n",
	    "<$deltaCacheDir> already exists. How to proceed:\n",
	    "overwrite / continue / stop -> ";
	    $answer = <STDIN>;
	    chomp $answer;
	} while ($answer ne 'overwrite' and $answer ne 'stop' and
		 $answer ne 'continue');
	if ($answer eq 'stop')
	{
	    exit 1;
	}
	elsif ($answer eq 'continue')
	{
	    $writeConfigFile = 0;
	}
    }

    if ($writeConfigFile)
    {
	my $l;
	local *IN, *OUT;
	open(IN, '<', $fIn) or
	    $prLog->print('-kind' => 'E',
		      '-str' => ["cannot open temporary file <$fIn>"],
			  '-exit' => 1);
	open(OUT, '>', $fOut) or
	    $prLog->print('-kind' => 'E',
			  '-str' => ["cannot open file <$fOut>"],
			  '-exit' => 1);
	while ($l = <IN>)
	{
	    chomp $l;
	    if ($l =~ /\A;(backupCopy0)=\s*\Z/)
	    {
		print OUT "$1='Backup Copy'" .
		    " '", join('\' \'', @$series), "'\n";
	    }
	    else
	    {
		print OUT "$l\n";
	    }
	}
	close(IN);
	close(OUT);
	$writtenConfFiles |= 4;
	$prLog->print('-kind' => 'I',
		      '-str' =>
		      ["wrote delta cache configuration file " .
		       "<$fOut>"]);
    }
}

$prLog->print('-kind' => 'W',
	      '-str' => ["not all configuration files were written,",
			 "so they might be inconsistent - please check"])
    unless $writtenConfFiles == (1|2|4);

# delete temporary files / directory
unlink "$tmpDir/storeBackupBaseTree.conf", "$tmpDir/deltaCache.conf";
rmdir $tmpDir;

exit 0;



##################################################
sub checkDir
{
    my ($dir, $name, $comment, $prLog) = @_;

    my $c = "\n";
    foreach my $l (&::splitLine($comment, 79, '\s+', "\n"))
    {
	$c .= "$l\n";
    }

    unless ($dir)
    {
	print $c;
	$c = undef;
	my $answer = '';
	do
	{
	    print "\n$name is not yet defined, please enter path\n",
	    "-> ";
	    $answer = <STDIN>;
	    chomp $answer;
	} while ($answer =~ /\A\s*\Z/);

	$dir = $answer;
    }

    unless (-e $dir)
    {
	print $c if $c;
	my $answer = undef;
	do
	{
	    print "\n$name does not exist at <$dir>\n",
	    "should I create it?\n",
	    "yes / no -> ";
	    $answer = <STDIN>;
	    chomp $answer;
	} while ($answer ne 'yes' and $answer ne 'no');

	exit 1 if $answer eq 'no';

	&::makeDirPath($dir, $prLog) or
	    $prLog->print('-kind' => 'E',
			  '-str' => ["cannot create $name <$dir>"],
			  '-exit' => 1);
	$prLog->print('-kind' => 'I',
		      '-str' => ["created $name <$dir>"]);
    }

    return $dir;
}


##################################################
sub cleanup
{
    my $signame = shift;
    my $exit = (shift() || 1);

    my ($prLog, $tmpDir) = (@main::cleanup);

    print "\n";
    if ($signame)
    {
        $prLog->print('-kind' => 'E',
                      '-str' => ["caught signal $signame, terminating"]);
    }

    # delete temporary files / directory
    if ($tmpDir)
    {
	unlink "$tmpDir/storeBackupBaseTree.conf", "$tmpDir/deltaCache.conf";
	rmdir $tmpDir;
    }

    exit $exit;
}