X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=backup.sh;h=b17ad65dffec7564860599e1f3c4e93614f85211;hb=dc3d68c24af006fb35d32043df6d8a710ea8a145;hp=0e230399b4ed6be81fe2767139520ce439642e49;hpb=2963d003c1f7b4795ee38443f1b47ce0c8a4daf8;p=backup.sh diff --git a/backup.sh b/backup.sh index 0e23039..b17ad65 100755 --- a/backup.sh +++ b/backup.sh @@ -77,8 +77,7 @@ backup() SNARFILE="${storagedir}/${computer}/${sfilesystem}/.incremental.snar" incrementalsnar="/root/.backup/${sfilesystem}.snar" - if [ "$backuplevel" = "daglig" ] - then + if [ "$backuplevel" = "daglig" ]; then # If incremental backup, we need to copy the incremental status to $computer. # If it does not exist, whine a bit and then run date-based instead. if [ -s "$SNARFILE" ]; then @@ -114,14 +113,18 @@ backup() if [ $? -eq 0 ] && [ -s $TARFILE ]; then # File is >0 in size and neither cat or tar tzvf failed; we assume it worked. - - if ! scp root@$computer:$incrementalsnar $SNARFILE.tmp; then - diemsg "Could not copy .incremental.snar from $computer" + + if [ "$incrementalsnar" ]; then + if ! scp root@$computer:$incrementalsnar $SNARFILE.tmp; then + diemsg "Could not copy .incremental.snar from $computer" + fi fi # Move tar file in place mv $TARFILE $DATE.tgz - mv $SNARFILE.tmp $SNARFILE + if [ "$incrementalsnar" ]; then + mv $SNARFILE.tmp $SNARFILE + fi # Update timestamp echo $DATEs > ../.date && touch -t $DATE ../.date @@ -202,8 +205,7 @@ if ! ssh root@$computer "[ ! -f /root/.backup/preexec ] || /bin/bash -x /root/.b diemsg "Could not run $computer:/root/.backup/preexec" fi -for filesystem in $filesystems -do +for filesystem in $filesystems; do # Remove / and $ (for Windows) for path names sfilesystem=`echo $filesystem | tr '\/\$' '__'` @@ -214,11 +216,9 @@ do # Default backuplevel backuplevel=daglig - if [ ! -f $storagedir/$computer/$sfilesystem/.date ] - then + if [ ! -s $storagedir/$computer/$sfilesystem/.date ]; then # Take the first full backup of this filesystem on this computer backuplevel=full - echo $DATEs > $storagedir/$computer/$sfilesystem/.date fi # Check if we want a full backup @@ -241,21 +241,22 @@ do fi # We want to be here - cd $storagedir/$computer/$sfilesystem/$backuplevelmsg || die "$storagedir/$computer/$sfilesystem/$backuplevel does not exist" + cd $storagedir/$computer/$sfilesystem/$backuplevel || diemsg "$storagedir/$computer/$sfilesystem/$backuplevel does not exist" # Perform the actual backup backup # Check if this box has a custom number of full backups - if [ -f $confdir/maksfulle.$computer ] ; then + if [ -f $confdir/maksfulle.$computer.$sfilesystem ]; then + mf=$((`cat $confdir/maksfulle.$computer`+1)) + elif [ -f $confdir/maksfulle.$computer ] ; then mf=$((`cat $confdir/maksfulle.$computer`+1)) else mf=$(($maxnumfull+1)) fi # Delete old full backups - for full in `ls -1t $storagedir/$computer/$sfilesystem/full/*tgz | tail -n +$mf` - do + for full in `ls -1t $storagedir/$computer/$sfilesystem/full/*tgz | tail -n +$mf`; do prefix=`echo $full | sed "s/\.[^.]*$//"` echo `date`": $computer:$filesystem Deleting full backup $prefix" >&2 rm $prefix* @@ -275,6 +276,9 @@ done if ! ssh root@$computer "[ ! -f /root/.backup/postexec ] || /bin/bash -x /root/.backup/postexec" >&2; then diemsg "Could not run $computer:/root/.backup/postexec" fi + +echo `date`": $computer: Backup completed successfully." +echo `date`": $computer: Backup completed successfully." >&2 # Remove lockfile rm $LOCKFILE