LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   *BSD (https://www.linuxquestions.org/questions/%2Absd-17/)
-   -   Script to backup system files (https://www.linuxquestions.org/questions/%2Absd-17/script-to-backup-system-files-486947/)

Kristijan 09-25-2006 08:22 PM

Script to backup system files
 
I'm looking at backing up configuration and other various files off my NetBSD box to my fileserver.

I've made an attempt to write up a script to do all this for me. I'm not at home at the moment, or infront of a BSD box, so I've just tried remembering commands and file paths from memory.

I'd appreciate some input on the following:
  1. What other files would I need to backup incase my hardware died and needed to rebuild from scratch (As quickly as possible).
  2. Am I using find correctly to locate the oldest file in the directory and remove it?

Code:

# OS: NetBSD 3.0.1
#
# Author: Kristijan
#
# Change Log:
#        26/09/06  - Initial write of script


##Variables##

USERNAME=kristijan
SERVERNAME=bart
BACKUP=${USERNAME}@${SERVERNAME}:backup
LOCALBACKUP=/tmp/backup
DATE=`date +%b%Y`
HOSTNAME=`hostname`


##Create /tmp/backup##
mkdir $LOCALBACKUP


##Copy files locally to be backed up##

pkg_info > $LOCALBACKUP/pkg_info.txt
ifconfig -a > $LOCALBACKUP/ifconfig.txt
crontab -u root -l > $LOCALBACKUP/root_crontab.txt
cp /etc/ssh/sshd_config $LOCALBACKUP
cp /etc/lkm.conf $LOCALBACKUP
cp /etc/rc.conf $LOCALBACKUP
cp /etc/pf.conf $LOCALBACKUP
cp /etc/dhcpd.conf $LOCALBACKUP
cp /etc/rc.d/rc.local $LOCALBACKUP
cp -r /root/scripts/* $LOCALBACKUP


##Remove backups which are older then 4 weeks##

ssh ${USERNAME}@${SERVERNAME} "find /home/kristijan/backup -iname *.tar.gz -mtime +28 -exec rm {}\;"


##Create package, send then remove##

tar -cvzf /tmp/${HOSTNAME}.${DATE}.tar.gz $LOCALBACKUP
scp /tmp/${HOSTNAME}.${DATE}.tar.gz $BACKUP
rm /tmp/${HOSTNAME}.${DATE}.tar.gz
rm -rf $LOCALBACKUP

Cheers,
-Kristijan

Kristijan 09-25-2006 08:57 PM

From the find man pages:

-mtime n
True if the difference between the file last modification time
and the time find was started, rounded up to the next full
24-hour period, is n 24-hour periods.


Could I do something like this for the line count?

Code:

if [ $linecnt -ge 5 ]
        then ssh data@bart "find /home/data/backup -mtime 27 -exec rm ();"
fi

I've set it for 27 24-hour periods just to be safe. Is the syntax correct?

-Kristijan

Kristijan 09-26-2006 11:24 PM

Script updated :)

Any advice and/or tips would be greatly appreciated.

-Kristijan

primo 10-01-2006 04:51 AM

Why not use the entire /etc and keep diffs if size matters to you ?
A daily pkg_info comes handy by using diffs, for example.
It's good to keep records of everything you do as root, dates and so on.


All times are GMT -5. The time now is 05:53 PM.