Re: Conf File Backup Idea

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2009-08-01 at 08:41 +0100, Terry Barnaby wrote:
> On 08/01/2009 04:58 AM, Tony Nelson wrote:
> > On 09-07-31 19:17:46, Thom Paine wrote:
> >> Thanks for the suggestions. I'll have a look at some of them and see
> >> if I can figure something out.
> >>
> >> I don't mind manually making lists of files as I start working with
> >> them. What really prompted this was that I have some home automation
> >> working really well on an old server I had. One power outtage that
> >> lasted longer than 30 minutes while I was away from home, two hard
> >> drives in the array went offline. I thought the whole server was lost
> >> and last night I dusted it off and rooted around in the adaptec
> >> interface and was able to force them both back online and bring the
> >> array back up. I quickly copied off my heyu files but I got to
> >> thinking if there was a way to automatically rsync files somewhere
> >> when I edit them, it would make things simpler on a server I have no
> >> need to completely back up, yet have some good info on it.
> >
> > I'm a sloppy person, so I set up an rsync-based solution derived from a
> > script I snagged through googling.  It keeps 4-hourly, daily, 4 weekly,
> > and several monthly rotating backups of the directories I list.  Let me
> > know if you want it.  Sometime I'll clean it up some more and put it on
> > my web site.
> >
> 
> Something that we do to get most of the configuration files backed up is:
> 
> # Create list of RPM config files that have changed
>  > files_rpmconfig
> rpm -qac --dump  | sed -e "/^(/d" | while read -a line
> do
> #	echo "Line: ${line[0]} ${line[3]}"
> 	if false
> 	then
> 		if [ ! -r ${line[0]} ]
> 		then
> 			echo "Unable to access file: ${line[0]}"
> 		fi
> 	fi
> 	if [ -f ${line[0]} ]
> 	then
> 		fi=(`md5sum ${line[0]}`)
> #		echo "Sum: ${fi[0]}"
> 		if [ ${fi[0]} != ${line[3]} ]
> 		then
> 			echo "${line[0]}" >> files_rpmconfig
> 		fi
> 	fi
> done
> 
> This should backup any files that are marked as configuration files in the RPM 
> packages and have changed. If you has installed tarballs etc, you will obviously
> have to add any configuration files for those manually. We normally do this
> during OS updates so we can quickly look back at configuration changes without
> having to go and get the full backup disk.
> 
> Cheers
> 
> 
> Terry
> 
Mine is a bit longer but I have found it very useful

Please triple check it suits your purpose before use !
Absolutely no warranty !

Three vital lines that do all the work are commented out below
for the -os and -or options 
#       print `$command`;######################################!!!!!!!!
The -oc option is enabled

The script started out of a list of vital files I needed to save
and restore when upgrading my server. It just grew!

Hope it helps

John
 

monk bin 215# cat maui_save_restore_compare.pl                                               
#!/usr/bin/perl -w                                                                           
#-os is used to save maui config files to a "safe" tar archive                               
#-or is used to restore maui config files from tar achive onto the same or a different machine
#-oc is used to compare existing config files on a machine with those in a maui "safe" tar archive
# The file list is that defined explicitly by a @list="..." statement or by the contents of a directory
# For the directory cases (/etc/samba, ...) the file list is dependent upon the option given           
# For -os the list is defined by the files present in that directory on the machine                    
# For -or and -oc the file set is defined by the files present in the "safe" directory 

############################################################################                       
#Must be run as root                                                                               
if (`whoami` ne "root\n"){die "I'm not root\n"};                                                   

require "getopts.pl";
&Getopts('o:');      
#print $opt_o,"\n";  

if( $opt_o  eq "" ){die "Must have single command line option -os, -or or -oc\n"};
if ( $opt_o  ne "s" &&  $opt_o  ne "r" &&  $opt_o  ne "c" ){die "Must have command line option -os, -or or -oc\n"};
############################################################################                                       
#Save the system files to directory safe                                                                           
if ( $opt_o  eq "s"){                                                                                              
        chdir;  #cd /root                                                                                          
#       print "pwd ",`pwd`;                                                                                        
        $safe="safe";                                                                                              
        if ( ! -d $safe ){ mkdir $safe;}                                                                           
        $options="-a --parents";                                                                                   
}                                                                                                                  
############################################################################                                       
#Restore the saved files from safe directory to the system - BE CAREFUL !!                                         
if ( $opt_o  eq "r"){                                                                                              
#       Must be run in directory containing directory "safe"                                                       
        if ( ! -d "safe" ){ die "No safe directory located here!\n";}                                              
        $options="-a";                                                                                             
}                                                                                                                  
############################################################################                                       
#Compare the system files with the saved files                                                                     
if ( $opt_o  eq "c"){                                                                                              
#       Must be run in directory containing directory "safe"                                                       
        if ( ! -d "safe" ){ die "No safe directory located here!\n";}                                              
}                                                                                                                  
############################################################################                                       
############################################################################                                       
sub save {                                                                                                         
my (@list) =@_;                                                                                                    
foreach $j (@list) {                                                                                               
        $command=sprintf "cp $options \"/$j\" \"$safe\"";                                                          
        print $command,"\n";                                                                                       
#       print `$command`;     ######################################!!!!!!!!                                                                                     
        }                                                                                                          
}                                                                                                                  
############################################################################                                       
sub restore {                                                                                                      
my (@list) =@_;                                                                                                    
foreach $j (@list) {                                                                                               
        if ( -e "/$j" ){                                                                                           
                $source="/$j"; $dest="/${j}_pre_restore";                                                          
#               print "source=" ,$source,"   dest= ",$dest,"\n";                                                   
                if ( ! -e "$dest" ){                                                                               
                        $command=sprintf "cp $options \"$source\" \"$dest\"";                                      
                        print $command,"\n";                                                                       
#                       print `$command`;######################################!!!!!!!!                                                                      
                        }                                                                                          
                $source="safe/$j"; $dest="/$j";                                                                    
                $command=sprintf "cp $options \"$source\" \"$dest\"";                                              
                print $command,"\n";                                                                               
#               print `$command`; ######################################!!!!!!!!                                                                                 
                }                                                                                                  
        }                                                                                                          
}                                                                                                                  
############################################################################                                       
#Compare system files with "safe" files.                                                                           
sub compare                                                                                                        
{                                                                                                                  
my (@list) =@_;                                                                                                    
foreach $j (@list) {                                                                                               
        $command=sprintf "diff \"/$j\" \"safe/$j\"";                                                               
        print $command,"\n";                                                                                       
        print `$command`;                                                                                          
        }                                                                                                          
}                                                                                                                  
############################################################################                                       
#Misc - Save and Compare Only.                                                                                     
print "---------------------------------------------------------------------------\n";                             
print "Misc - Save and Compare Only\n";                                                                            
@list=("etc/sysconfig/network-scripts/ifcfg-eth0","etc/fstab","etc/rc.d/rc.local",                                 
"usr/sbin/ssd_schedule_change.pl");                                                                                
if($opt_o eq "s"){save (@list)};                                                                                   
#                                                                                                                  
if($opt_o eq "c"){compare (@list)};                                                                                

#Authentication
print "---------------------------------------------------------------------------\n";
print "Authentication\n";                                                             
@list=("etc/passwd","etc/group","etc/shadow","etc/gshadow");                          
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#Cyrus
print "---------------------------------------------------------------------------\n";
print "Cyrus\n";                                                                      
@list=("etc/cyrus.conf","etc/imapd.conf");                                            
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#Dhcpd
print "---------------------------------------------------------------------------\n";
print "Dhcpd\n";                                                                      
@list=("etc/dhcpd.conf");                                                             
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#Exim
print "---------------------------------------------------------------------------\n";
print "Exim\n";                                                                       
@list=("etc/exim/exim.conf","etc/aliases");                                           
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#DDNS
print "---------------------------------------------------------------------------\n";
print "DDNS\n";                                                                       
@list=("var/named/chroot/var/named/jaa.org.uk.zone","var/named/chroot/var/named/148.197.29.zone",
"var/named/chroot/etc/named.conf","etc/sysconfig/named");                                        
if($opt_o eq "s"){save (@list)};                                                                 
if($opt_o eq "r"){restore (@list)};                                                              
if($opt_o eq "c"){compare (@list)};                                                              

#Static Networking
print "---------------------------------------------------------------------------\n";
print "Static Networking\n";                                                          
@list=("etc/hosts","etc/sysconfig/network","etc/nsswitch.conf","etc/resolv.conf");    
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#NFS
print "---------------------------------------------------------------------------\n";
print "NFS\n";                                                                        
@list=("etc/exports","etc/sysconfig/nfs","etc/idmapd.conf");                          
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#Automounter
print "---------------------------------------------------------------------------\n";
print "Automounter\n";                                                                
@list=("etc/auto.direct","etc/auto.home","etc/auto.master","etc/exports",             
"etc/sysconfig/autofs","etc/sysconfig/nfs");                                          
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#NIS
print "---------------------------------------------------------------------------\n";
print "NIS\n";                                                                        
@list=("var/yp/Makefile","var/yp/securenets","etc/yp.conf");                          
if($opt_o eq "s"){save (@list)};                                                      
if($opt_o eq "r"){restore (@list)};                                                   
if($opt_o eq "c"){compare (@list)};                                                   

#Apache and Squirrel Mail
print "---------------------------------------------------------------------------\n";
print "Apache and Squirrel Mail\n";
@list=("etc/httpd/conf/httpd.conf","etc/httpd/conf.d/squirrelmail.conf",
"etc/squirrelmail/config.php","usr/share/squirrelmail/src/login.php");
if($opt_o eq "s"){save (@list)};
if($opt_o eq "r"){restore (@list)};
if($opt_o eq "c"){compare (@list)};

#Samba
#Process /etc/samba directory
print "---------------------------------------------------------------------------\n";
print "Prossessing /etc/samba\n";
if($opt_o eq "s"){
        @newlist=();
        @list=`find /etc/samba -type f -print`;
        foreach $j (@list){$j=~ s#^/##;chop $j;push(@newlist,$j);};
        save (@newlist);
        }
if($opt_o eq "r" || $opt_o eq "c"){
        @newlist=();
        @list=`find safe/etc/samba -type f -print`;
        foreach $j (@list){$j=~ s#^safe/##;chop $j;push(@newlist,$j);};
        }
if($opt_o eq "r"){restore (@newlist)};
if($opt_o eq "c"){compare (@newlist)};

#Process /var/lib/samba directory
print "---------------------------------------------------------------------------\n";
print "Processing /var/lib/samba\n";
if($opt_o eq "s"){
        @newlist=();
        @list=`find /var/lib/samba -type f -print`;
        foreach $j (@list){$j=~ s#^/##;chop $j;push(@newlist,$j);};
        save (@newlist);
        }
if($opt_o eq "r" || $opt_o eq "c"){
        @newlist=();
        @list=`find safe/var/lib/samba -type f -print`;
        foreach $j (@list){$j=~ s#^safe/##;chop $j;push(@newlist,$j);};
        }
if($opt_o eq "r"){restore (@newlist)};
if($opt_o eq "c"){compare (@newlist)};




-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux