btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / st / storeBackup / package.nix
blob74c867e9ec5e501d21c7380153570050f84a0198
1 {lib, stdenv, which, coreutils, perl, fetchurl, makeWrapper, diffutils , writeScriptBin, bzip2}:
3 # quick usage:
4 # storeBackup.pl --sourceDir /home/user --backupDir /tmp/my_backup_destination
5 # Its slow the first time because it compresses all files bigger than 1k (default setting)
6 # The backup tool is bookkeeping which files got compressed
8 # btrfs warning: you may run out of hardlinks soon
10 # known impurity: test cases seem to bu using /tmp/storeBackup.lock ..
12 let dummyMount = writeScriptBin "mount" "#!${stdenv.shell}";
15 stdenv.mkDerivation rec {
17   version = "3.5.2";
19   pname = "store-backup";
21   enableParallelBuilding = true;
23   nativeBuildInputs = [ makeWrapper ];
24   buildInputs = [ perl ];
26   src = fetchurl {
27     url = "https://download.savannah.gnu.org/releases/storebackup/storeBackup-${version}.tar.bz2";
28     hash = "sha256-Ki1DT2zypFFiiMVd9Y8eSX7T+yr8moWMoALmAexjqWU=";
29   };
31   patches = [
32     # https://www.openwall.com/lists/oss-security/2020/01/20/3
33     ./CVE-2020-7040.patch
34   ];
36   installPhase = ''
37     mkdir -p $out/scripts
38     mv * $out
39     mv $out/_ATTENTION_ $out/doc
40     mv $out/{correct.sh,cron-storebackup} $out/scripts
42     find $out -name "*.pl" | xargs sed -i \
43       -e 's@/bin/pwd@${coreutils}/bin/pwd@' \
44       -e 's@/bin/sync@${coreutils}/bin/sync@' \
45       -e '1 s@/usr/bin/env perl@${perl.withPackages (p: [ p.DBFile ])}/bin/perl@'
47     for p in $out/bin/*
48       do wrapProgram "$p" --prefix PATH ":" "${lib.makeBinPath [ which bzip2 ]}"
49     done
51     patchShebangs $out
52     # do a dummy test ensuring this works
54     PATH=$PATH:${dummyMount}/bin
56     export USER=test
57     export HOME=$(mktemp -d)
58     { # simple sanity test, test backup/restore of simple store paths
60       mkdir backup
62       backupRestore(){
63         source="$2"
64         echo =========
65         echo RUNNING TEST "$1" source: "$source"
66         mkdir restored
68         $out/bin/storeBackup.pl --sourceDir "$source" --backupDir backup
69         latestBackup=backup/default/$(ls -1 backup/default | sort | tail -n 1)
70         $out/bin/storeBackupRecover.pl -b "$latestBackup" -t restored -r /
71         ${diffutils}/bin/diff -r "$source" restored
73         # storeBackupCheckSource should return 0
74         $out/bin/storeBackupCheckSource.pl -s "$source" -b "$latestBackup"
75         # storeBackupCheckSource should return not 0 when using different source
76         ! $out/bin/storeBackupCheckSource.pl -s $TMP -b "$latestBackup"
78         # storeBackupCheckBackup should return 0
79         $out/bin/storeBackupCheckBackup.pl -c "$latestBackup"
81         chmod -R +w restored
82         rm -fr restored
83       }
85       testDir=$TMP/testDir
87       mkdir $testDir
88       echo X > $testDir/X
89       ln -s ./X $testDir/Y
91       backupRestore 'test 1: backup, restore' $testDir
93       # test huge blocks, according to docs files bigger than 100MB get split
94       # into pieces
95       dd if=/dev/urandom bs=100M of=block-1 count=1
96       dd if=/dev/urandom bs=100M of=block-2 count=1
97       cat block-1 block-2 > $testDir/block
98       backupRestore 'test 1 with huge block' $testDir
100       cat block-2 block-1 > $testDir/block
101       backupRestore 'test 1 with huge block reversed' $testDir
103       backupRestore 'test 2: backup, restore' $out
104       backupRestore 'test 3: backup, restore' $out
105       backupRestore 'test 4: backup diffutils to same backup locations, restore' ${diffutils}
106     }
107   '';
109   meta = {
110     description = "Backup suite that stores files on other disks";
111     homepage = "https://savannah.nongnu.org/projects/storebackup";
112     license = lib.licenses.gpl3Plus;
113     maintainers = [lib.maintainers.marcweber];
114     platforms = lib.platforms.linux;
115   };