#!/bin/sh # simple backup utility by Nick Manini - v. Oct 2020 # to be run as cron command at non-hurting (night) times # potential problem: keeps overwriting the same file on backupmachine # over and over again: if crash during backup then all is lost # cure: weekly or monthly copy the backupfile to another name or dir # (could be automated...) backupdirectory=/home/manini # the local directory to backup excludeddirectoryfile="EXCLUDE_FROM_BACKUP" # put this file in a directory not intended for backup prefix=all.`basename $backupdirectory`.`hostname` tmpdir=/scratch #tmpdir=~/scratch # temporary solution tarf=$prefix.tgz ttarf=$tmpdir/$tarf backupmachine=pga # the remote machine copycommand="scp " # rcp or scp # (setup either .rhost or .ssh/authorized_keys so that no passwd is asked!) remoteshell="ssh "; # rsh or ssh work - configure correcly! remoterun="$remoteshell $backupmachine -n"; umask 077 # set very safe priorities #rm $ttarf $tmpdir/$prefix[a-z][a-z] #echo backup suspended!! #exit 1 echo "backup of $backupdirectory -> $backupmachine starting on "`date` tar czf $ttarf --exclude-tag-all=$excludeddirectoryfile $backupdirectory tarRV=$? if (test $tarRV -lt 2) then # check for correct tar-gzipping before messing up the backup if(test $tarRV -eq 1) then echo "Warning, some file may have changed and not entered in tar" fi if($copycommand $ttarf $backupmachine:) then rm $ttarf # cleanup on successful completion else date echo $copycommand error! could not copy the tar file! echo leaving local copy $tmpdir/$ttarf for investigation echo terminating here exit 3 fi else date echo tar error! leaving the $ttarf file uncopied for investigation echo terminating here exit 1 fi echo backup completed successfully on `date`