Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Horrid Gentoolkit *Bug* = ?
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed May 15, 2002 8:05 am    Post subject: Reply with quote

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
Apprentice


Joined: 20 Apr 2002
Posts: 253
Location: Chantilly, VA

PostPosted: Wed May 15, 2002 2:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
lunatc
Guru
Guru


Joined: 18 Apr 2002
Posts: 409
Location: Canary Islands. Spain

PostPosted: Wed May 15, 2002 11:25 pm    Post subject: + Reply with quote

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
View user's profile Send private message
proxy
Apprentice
Apprentice


Joined: 20 Apr 2002
Posts: 253
Location: Chantilly, VA

PostPosted: Wed May 15, 2002 11:33 pm    Post subject: Reply with quote

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 :P
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum