LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices



Reply
 
Search this Thread
Old 09-25-2006, 09:22 PM   #1
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
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

Last edited by Kristijan; 09-27-2006 at 12:45 AM.
 
Old 09-25-2006, 09:57 PM   #2
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Original Poster
Rep: Reputation: 30
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
 
Old 09-27-2006, 12:24 AM   #3
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Original Poster
Rep: Reputation: 30
Script updated

Any advice and/or tips would be greatly appreciated.

-Kristijan
 
Old 10-01-2006, 05:51 AM   #4
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to remove backup ~ files hallamigo Linux - General 3 09-13-2010 04:47 PM
text files and their automatic backup files AGazzaz Linux - General 1 07-01-2006 08:38 AM
Deleting backup files in my system. hgb Linux - Software 6 11-07-2005 01:15 AM
Bash backup script - If multiple files starting with a exist problem demoncheese Programming 2 07-29-2004 11:47 PM
SCRIPT: backup defined files/dirs to FTP-server markus1982 Linux - Software 0 05-25-2003 07:06 AM


All times are GMT -5. The time now is 07:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration