Friday, 10 September 2010

Linux backup

Backup files and databases to Linux box via scp with encryption and email notification

#!/bin/sh.
#Backup server options
server=11.11.11.111
user=user
key=/path/key.key
port=22222
backup_dir=/path/


#Archive options
date=`date +%F`
arc_name=arc_$date
tar_dir=/path
data="/var/www/ /etc"
days=22
logfile=/var/log/backup.log
admin=admin@domain.com



#Database options
mysql_u=user
mysql_p=password
databases=database




#Encryption options
gpg_key=email 



mysqldump --add-drop-table -u $mysql_u -p$mysql_p $databases > $tar_dir/$date.db 2>>$logfile &&

tar czf - --exclude={*.tar.gz,*.sql} --ignore-failed-read $tar_dir/$date.db $data > $tar_dir/$arc_name.tar.gz  | gpg -e -r $gpg_key > $arc_name-$date.tar.gz.gpg 2>>$logfile


 /usr/bin/scp -P $port -i $key $tar_dir/$arc_name.tar.gz.gpg $user@$server:$backup_dir 2>>$logfile &&
find $tar_dir -mtime +$days -exec rm {} \; 2>>$logfile &&
echo "$date - Backup successfull" >> $logfile ||
echo "There are some problems with backup on $arc_name" | mail -s "Backup: $arc_name problems" $admin

Backup data and databases to windows share folder

This small script encrypts and backups data and mysql databases to windows share using CIFS protocol. It also logs it's operations and sends notifications to administrator in case of problems.


#!/bin/sh 



#CIFS server options 

server= 

folder= 

user= 

pass= 

domain=DOMAIN 



#Logs and notifications options 

admin=Administrator e-mail 

logfile=/var/log/backup.log 



#Encryption options 

key=GPG public key ID

#Archive options 

arc_name=The name of archive 

backup_dir=where to store database copies 

data="what files and directories to backup" 

mountpoint=/mnt/backup days=10 - how many days to store archives 

date=`date +%d-%m-%Y` - date format 



#Mysql options 

databases="database1 database2" 

mysql_user=root 

mysql_pass=root 



mount.cifs //$server/$folder $mountpoint -ouser=$user,pass=$pass domain=$domain 2>>$logfile &&
/usr/bin/mysqlhotcopy --addtodest --user=$mysql_user --password=$mysql_pass $databases $backup_dir/db 2>>$logfile && 

tar czf - $data $backup_dir/db | gpg -e -r $key > $mountpoint/$arc_name-$date.tar.gz.gpg 2>>$logfile &&
find $mountpoint -mtime +$days -exec rm {} \; 2>>$logfile &&

umount -f $mountpoint 2>>$logfile || 

echo "There are some problems with backup on $arc_name" | mail -s "$arc_name backup problems" $admin

Ping does not work

Today I would like to discuss a banal situation: host A is directly connected to host B, ping from host A to host B does not work. What are...