at release-16.03-start 111 lines 3.5 kB view raw
1{stdenv, which, coreutils, perl, fetchurl, perlPackages, makeWrapper, diffutils , writeScriptBin, bzip2}: 2 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 7 8# btrfs warning: you may run out of hardlinks soon 9 10# known impurity: test cases seem to bu using /tmp/storeBackup.lock .. 11 12let dummyMount = writeScriptBin "mount" "#!/bin/sh"; 13in 14 15stdenv.mkDerivation rec { 16 17 version = "3.5"; 18 19 name = "store-backup-${version}"; 20 21 enableParallelBuilding = true; 22 23 buildInputs = [ perl makeWrapper ]; 24 25 src = fetchurl { 26 url = "http://download.savannah.gnu.org/releases/storebackup/storeBackup-${version}.tar.bz2"; 27 sha256 = "0y4gzssc93x6y93mjsxm5b5cdh68d7ffa43jf6np7s7c99xxxz78"; 28 }; 29 30 installPhase = '' 31 mkdir -p $out/scripts 32 mv * $out 33 mv $out/_ATTENTION_ $out/doc 34 mv $out/{correct.sh,cron-storebackup} $out/scripts 35 36 find $out -name "*.pl" | xargs sed -i \ 37 -e 's@/bin/pwd@${coreutils}/bin/pwd@' \ 38 -e 's@/bin/sync@${coreutils}/bin/sync@' \ 39 -e '1 s@/usr/bin/env perl@${perl}/bin/perl@' 40 41 for p in $out/bin/* 42 do wrapProgram "$p" \ 43 --prefix PERL5LIB ":" "${perlPackages.DBFile}/lib/perl5/site_perl" \ 44 --prefix PATH ":" "${which}/bin:${bzip2}/bin" 45 done 46 47 patchShebangs $out 48 # do a dummy test ensuring this works 49 50 PATH=$PATH:${dummyMount}/bin 51 52 53 { # simple sanity test, test backup/restore of simple store paths 54 55 mkdir backup 56 57 backupRestore(){ 58 source="$2" 59 echo ========= 60 echo RUNNING TEST "$1" source: "$source" 61 mkdir restored 62 63 $out/bin/storeBackup.pl --sourceDir "$source" --backupDir backup 64 latestBackup=backup/default/$(ls -1 backup/default | sort | tail -n 1) 65 $out/bin/storeBackupRecover.pl -b "$latestBackup" -t restored -r / 66 ${diffutils}/bin/diff -r "$source" restored 67 68 # storeBackupCheckSource should return 0 69 $out/bin/storeBackupCheckSource.pl -s "$source" -b "$latestBackup" 70 # storeBackupCheckSource should return not 0 when using different source 71 ! $out/bin/storeBackupCheckSource.pl -s $TMP -b "$latestBackup" 72 73 # storeBackupCheckBackup should return 0 74 $out/bin/storeBackupCheckBackup.pl -c "$latestBackup" 75 76 chmod -R +w restored 77 rm -fr restored 78 } 79 80 testDir=$TMP/testDir 81 82 mkdir $testDir 83 echo X > $testDir/X 84 ln -s ./X $testDir/Y 85 86 backupRestore 'test 1: backup, restore' $testDir 87 88 # test huge blocks, according to docs files bigger than 100MB get split 89 # into pieces 90 dd if=/dev/urandom bs=100M of=block-1 count=1 91 dd if=/dev/urandom bs=100M of=block-2 count=1 92 cat block-1 block-2 > $testDir/block 93 backupRestore 'test 1 with huge block' $testDir 94 95 cat block-2 block-1 > $testDir/block 96 backupRestore 'test 1 with huge block reversed' $testDir 97 98 backupRestore 'test 2: backup, restore' $out 99 backupRestore 'test 3: backup, restore' $out 100 backupRestore 'test 4: backup diffutils to same backup locations, restore' ${diffutils} 101 } 102 ''; 103 104 meta = { 105 description = "A backup suite that stores files on other disks"; 106 homepage = http://savannah.nongnu.org/projects/storebackup; 107 license = stdenv.lib.licenses.gpl3Plus; 108 maintainers = [stdenv.lib.maintainers.marcweber]; 109 platforms = stdenv.lib.platforms.linux; 110 }; 111}