Simple Backup

From INIwiki
Jump to: navigation, search

Contents

[edit] Apache

[edit] RedHat Based

#! /bin/bash

date=`date +%m-%d-%Y`
date1=`date +%Y%m%d-%H:%M:%S`

echo "#################################################" >> /var/log/bu_web.log
echo Backup  Start at: $date1 >> /var/log/bu_web.log
echo Backup  inisec at: $date1 >> /var/log/bu_web.log
tar -pcjvf /archive/bu_web.inisec.drupal-$date.tgz2 /var/www/html/inisec/drupal
tar -pcjvf /archive/bu_web.inisec.wiki-$date.tgz2 /var/www/html/inisec/wiki
tar -pcjvf /archive/bu_web.inisec.inisec-$date.tgz2 /var/www/html/inisec/inisec.com
/usr/bin/rsync -avP /archive/bu_web.inisec* /mnt/inidc01/inisec/web/

echo Backup clsfamily at: $date1 >> /var/log/bu_web.log
tar -pcjvf /archive/bu_web.clsfamily-$date.tgz2 /var/www/html/clsfamily
tar -pcjvf /archive/bu_web.clsfamilyfiles-$date.tgz2 /var/clsdrupaldata
/usr/bin/rsync -avP /archive/bu_web.clsfamily* /mnt/inidc01/inisec/web/

echo Backup httpd.conf at: $date1 >> /var/log/bu_web.log
/usr/bin/rsync -avP /etc/httpd/conf/httpd.conf /mnt/inidc01/inisec/web/

echo Backup conf.d at: $date1 >> /var/log/bu_web.log
/usr/bin/rsync -avP /etc/httpd/conf.d/ /mnt/inidc01/inisec/web/conf.d

echo Remove Archives at: $date1 >> /var/log/bu_web.log
rm -rf /archive/bu_web.inisec*
rm -rf /archive/bu_web.clsfamily*
echo Backup Complete at: $date1 >> /var/log/bu_web.log
echo "#################################################" >> /var/log/bu_web.log
echo  >> /var/log/bu_web.log

[edit] Debian Based

#! /bin/bash
date=`date +%Y-%m-%d`
dateL=`date +%Y%m%d-%H:%M:%S`
host=`hostname -f`

### COMPRESS COPY START ###
echo "#################################################" >> /var/log/bu_files.log
echo Backup Config Files START: $dateL >> /var/log/bu_files.log

## Comment out what is not needed ##
tar -pczf /archive/$host-bu_dansG-$date.tar.gz /etc/dansguardian*
tar -pczf /archive/$host-bu_shorewall-$date.tar.gz /etc/shorewall
tar -pczf /archive/$host-bu_bind-$date.tar.gz /etc/bind
tar -pczf /archive/$host-bu_dhcpd-$date.tar.gz /etc/dhcp3
tar -pczf /archive/$host-bu_openvpn-$date.tar.gz /etc/openvpn
tar -pczf /archive/$host-bu_squid-$date.tar.gz /etc/squid /usr/bin/adzapper.wrapper
tar -pczf /archive/$host-bu_bridgescripts-$date.tar.gz /scripts/bridge.sh
tar -pczf /archive/$host-bu_inistuff-$date.tar.gz /root/ini_stuff
tar -pczf /archive/$host-bu_tftpserver-$date.tar.gz /tftpserver
tar -pczf /archive/$host-bu_scripts-$date.tar.gz /scripts
tar -pczf /archive/$host-bu_www-$date.tar.gz /var/www /etc/apache2/apache2.conf
tar -pczf /archive/$host-bu_interfaces-$date.tar.gz /etc/network/interfaces
tar -pczf /archive/$host-bu_cron-$date.tbz2 /etc/cron* /var/spool/cron/root
tar -pczf /archive/$host-bu_nagiosfiles-$date.tbz2 /usr/local/nagios
tar -pczf /archive/$host-_mrtg-$date.tbz2 /usr/local/mrtg-2
/etc/init.d/mysql stop
tar -pczf /archive/$host-bu_mysql_flatfile-$date.tar.gz /var/lib/mysql
/etc/init.d/mysql start

#echo FTP File Transfer to MS server: $dateL >> /var/log/bu_files.log
SOURCE_DIR=/archive
DEST_DIR=<FTP_TARGET_PATH>
USER=backup
PASSWORD="<PASSWORD>"
REMOTE_BOX=<IPADDRESS>
#FILE=test.file
cd $SOURCE_DIR
ftp -niv $REMOTE_BOX <<EOF
user $USER $PASSWORD
bin
cd $DEST_DIR
mput *.tar.gz
EOF
rm -rf /archive/*.tar.gz

[edit] MySQL

[edit] Create mySQL backup user

GRANT SHOW DATABASES, SELECT, LOCK TABLES, RELOAD ON *.* to backup@localhost
 IDENTIFIED BY 'readonly';
FLUSH PRIVILEGES;

[edit] mySQL dump Backup

#!/bin/sh

DIR=/backup/mysql/
DATESTAMP=$(date +%Y%m%d)
DB_USER=backup
DB_PASS='readonly'

# remove backups older than $DAYS_KEEP
DAYS_KEEP=30
find ${DIR}* -mtime +$DAYS_KEEP -exec rm -f {} \; 2> /dev/null

# create backups securely
umask 006

# list MySQL databases and dump each
DB_LIST=`mysql -u $DB_USER -p"$DB_PASS" -e'show databases;'`
DB_LIST=${DB_LIST##Database}
for DB in $DB_LIST;
do
  FILENAME=${DIR}${DB}-${DATESTAMP}.sql.gz
  mysqldump -u $DB_USER -p"$DB_PASS" --opt --flush-logs $DB | gzip > $FILENAME
done

[edit] Flat File Based

[edit] RedHat Based

#! /bin/bash
date=`date +%m-%d-%Y`
dateS=`date +%Y%m%d-%H:%M:%S`
dateE=`date +%Y%m%d-%H:%M:%S` 

###  FLAT COPY START ###
#/sbin/service mysqld stop
#/usr/bin/rsync -avP /var/lib/mysql/ /mnt/inidc01/inisec/bu_mysql/
#/sbin/service mysqld start
### FLAT COPY END ###

### COMPRESS COPY START ###
echo "#################################################" >> /var/log/bu_mysql.log
echo Backup MYSQL START $dateS >> /var/log/bu_mysql.log
/sbin/service mysqld stop
tar -pcjvf /archive/bu_mysql-$date.tgz2 /var/lib/mysql/
/usr/bin/rsync -avP /archive/bu_mysql* /mnt/inidc01/inisec/mysql/
/sbin/service mysqld start
echo Backup MYSQL END $dateE >> /var/log/bu_mysql.log
echo Remove Archives at: $date1 >> /var/log/bu_mysql.log
rm -rf /archive/bu_mysql*
### COMPRESS COPY END ###

[edit] Debian Based

[edit] Squid

[edit] OpenVPN

[edit] Sources/Other

http://www.debianhelp.co.uk/backup.htm
Old Local Source File
Personal tools