View previous topic :: View next topic |
Author |
Message |
Guest
|
Posted: Wed May 15, 2002 8:05 am Post subject: |
|
|
Code: |
#!/sbin/runscript
# Backs up /etc/*
start() {
local BACKUPDIR="/var/backup"
local DATE=`date +%Y%m%d`
local files=`ls -r ${BACKUPDIR}/etc*.tar.gz`
ebegin "Backing up /etc/* to ${BACKUPDIR}/etc-${DATE}.tar.gz"
if [ ! -d ${BACKUPDIR} ]
then
mkdir ${BACKUPDIR}
chmod 700 ${BACKUPDIR}
fi
backup=3
for arg in ${files}
do
if [ "${backup}" -le 0 ]
then
rm -f ${arg}
else
backup=$((${backup} -1))
fi
done
tar -Pzcspf ${BACKUPDIR}/etc-${DATE}.tar.gz /etc
chmod 700 ${BACKUPDIR}/etc-${DATE}.tar.gz
eend $?
}
|
For security reasons you should chmod /var/backup and the backup file. Users could copy the backup over and untar it and have a nice readable shadow file. |
|
Back to top |
|
|
proxy Apprentice
Joined: 20 Apr 2002 Posts: 260 Location: Chantilly, VA
|
Posted: Wed May 15, 2002 2:16 pm Post subject: |
|
|
anyone else for making such a script part of the base install or the gentoolkit package? I mean it wouldn't be "Active" until the user does an rc-update to add it to the ini anyway....so why not make a standard tool for backup the ever so important /etc directory? |
|
Back to top |
|
|
lunatc Guru
Joined: 18 Apr 2002 Posts: 409 Location: Canary Islands. Spain
|
Posted: Wed May 15, 2002 11:25 pm Post subject: + |
|
|
Here is my contribution:
1.- Don't show any message such 'file not found' when run for the first time (as first make the tar.bz and then check for files)
2.- Added hour-minute-and-second to the tar name so we can run at any time (with /etc/init.d/backup-etc restart) and still stores the three last tar.bz's
Code: |
#!/sbin/runscript
# Backs up /etc/*
# Put this script in /etc/init.d and perform the following:
# chmod 0755 /etc/init.d/backup-etc
# rc-update add backup-etc default
start() {
local BACKUPDIR="/var/backup"
local DATE=`date +%Y%m%d-%H%M%S`
ebegin "Backing up /etc/* to ${BACKUPDIR}/etc-${DATE}.tar.gz"
if [ ! -d ${BACKUPDIR} ]
then
mkdir -p ${BACKUPDIR}
chmod 700 ${BACKUPDIR}
fi
tar -Pzcspf ${BACKUPDIR}/etc-${DATE}.tar.gz /etc
local files=`ls -r ${BACKUPDIR}/etc*.tar.gz`
backup=3
for arg in ${files}
do
if [ "${backup}" -le 0 ]
then
rm -f ${arg}
else
backup=$((${backup} -1))
fi
done
chmod 700 ${BACKUPDIR}/etc-${DATE}.tar.gz
eend $?
}
|
|
|
Back to top |
|
|
proxy Apprentice
Joined: 20 Apr 2002 Posts: 260 Location: Chantilly, VA
|
Posted: Wed May 15, 2002 11:33 pm Post subject: |
|
|
how about changing
chmod 700 ${BACKUPDIR}/etc-${DATE}.tar.gz
to
chmod 600 ${BACKUPDIR}/etc-${DATE}.tar.gz
no need to make it have executable permissions |
|
Back to top |
|
|
|