data-center-soc-noc , o-s

Sample – Unix – Nightly backup script

June 28, 2016

Unix – Nightly backup script

For the nightly backup, UNIX’s find has an option to identify files newer than a named file.
(Tar has a newer than date option but the format doesn’t seem to be documented and I’ve never
found the right format.) I created a zero byte root only readable /etc/installed with a time stamp
just after the end of the last Linux install. A similar marker file could be used following a full
backup which could be done instead of the postinstall tar but this would take a lot more media.

#
#
# Anyone may use or modify this code for any purpose PROVIDED
# that as long as it is recognizably derived from this code,
# that this copyright notice, remains intact and unchanged.
# No warrantees of any kind are expressed or implied.
#
# Most of the time tar is run with the -r, append, option but the
# tar file must first be created before this can be used. Any small
# file in a known location will do hence /etc/shells.
cd /var/local/backup
tar -cvf backup /etc/shells >backup.log
/usr/bin/find /bin -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /etc -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /home -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /lib -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /root -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /usr -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /sbin -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/db -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/gdm -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/lib -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/local/downloads -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/local/logs -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/log -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/named -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/nis -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/preserve -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/state -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log
/usr/bin/find /var/yp -type f -newer /etc/installed -exec tar -rvf backup {} \; >>backup.log

chgrp wheel backup*
chmod 640 backup*
mv backup `date +%y%m%d`.tar
gzip `date +%y%m%d`.tar
mv backup.log `date +%y%m%d`.log

. /usr/local/bin/backup_to_other

 

Sample only – Always verify scripts run on your systems