Mass chattr and crontab backup examples

"Nathan G. Grennan" <[email protected]>
Newsgroups gmane.comp.sysutils.backup.hdup.general
Organization Cygnus X-1
Message-ID <[email protected]>
Here is a simple script to chattr +i all files with a certain last
extension under a certain directory. You can remove the \ and put it all
on one line. I added it in this message to make it clear that it is all
one line.

This script is useful for protecting backups from crackers that have
jumped from server to backup server via public key authentication and
might be looking to delete backups. It can be setup to run as a cron job
after all the backups have finished.

# Example for /etc/crontab
0 12 1-31 * * root /usr/local/sbin/bchattr /home


Usage: bchattr directory extension

Examples: bchattr /home nc
          bchattr /home bz2
          bchattr /home gz
 

#!/bin/bash
                                                            
/usr/bin/find $1 -type f -name "*.$2" | /usr/bin/xargs -i \
/usr/bin/chattr +i {}


I took the examples I found on the project website and optimized them to
reduce redundancy. The main reason was to streamline the monthly backup
to reduce the time it took. When you have a nightly window and many
servers time is precious. It doesn't look as pretty in crontab, but I am
happier with it.


Examples from /etc/crontab

# Monthly backup
0 0 1 * * root /usr/local/sbin/bmonth news
  
# Weekly backup
0 0 7,14,21,28 * 0 root /usr/local/sbin/bweek news
  
# Daily backup
0 0
2,3,4,5,6,8,9,10,11,12,13,15,16,17,18,19,20,22,23,24,25,26,27,29,30,31 *
* root /usr/local/sbin/bday news


If you had more than one backup server you could easily add a second
command line variable to fill in the hostname.


Example of bday:

#!/bin/bash
 
/usr/sbin/hdup -q -q daily $1 @$1-Yrl0mwjbw3JWVPTZF4YnfwC/[email protected]


Example of bmonth:

#!/bin/bash
 
/usr/sbin/hdup -q -q monthly $1 @$1-Yrl0mwjbw3JWVPTZF4YnfwC/[email protected]
/usr/sbin/hdup -q -q weekly $1 @$1-Yrl0mwjbw3JWVPTZF4YnfwC/[email protected]


Example of bweek:

#!/bin/bash
 
/usr/sbin/hdup -q -q weekly $1 @$1-Yrl0mwjbw3JWVPTZF4YnfwC/[email protected]



Anyone have any suggestions or comments?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.