Category Archives: rsync/backup

Percona Streaming Backup


SERVER B (192.168.0.140)

[root@alfamart ~]# rpm -aq | grep Percona
Percona-Server-shared-55-5.5.27-rel28.1.296.rhel6.x86_64
Percona-Server-55-debuginfo-5.5.27-rel28.1.296.rhel6.x86_64
Percona-Server-client-55-5.5.27-rel28.1.296.rhel6.x86_64
Percona-Server-server-55-5.5.27-rel28.1.296.rhel6.x86_64
Percona-Server-devel-55-5.5.27-rel28.1.296.rhel6.x86_64
Percona-Server-test-55-5.5.27-rel28.1.296.rhel6.x86_64
Percona-Server-shared-compat-5.5.27-rel28.1.296.rhel6.x86_64

[root@alfamart ~]# innobackupex -v
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2012. All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
[root@alfamart ~]# mysql –version
mysql Ver 14.14 Distrib 5.5.27, for Linux (x86_64) using readline 5.1
[root@alfamart ~]# ls -l /var/lib/mysql
total 28864
-rw-rw—- 1 mysql mysql 5 Oct 17 22:43 alfamart.pid
drwx—— 2 mysql mysql 4096 Oct 13 13:18 percona
drwx—— 2 mysql mysql 4096 Oct 11 01:01 percona_addons
drwx—— 2 mysql mysql 4096 Oct 11 01:01 percona_report
-rwx—— 1 mysql mysql 18874368 Oct 17 22:43 ibdata1
-rw-rw—- 1 mysql mysql 5242880 Oct 17 22:43 ib_logfile0
-rw-rw—- 1 mysql mysql 5242880 Oct 11 01:01 ib_logfile1
drwx—— 2 mysql mysql 4096 Oct 11 01:01 mysql
srwxrwxrwx 1 mysql mysql 0 Oct 17 22:43 mysql.sock
drwx—— 2 mysql mysql 4096 Oct 12 13:50 oshop_gc
drwx—— 2 mysql mysql 4096 Oct 11 01:01 performance_schema
-rwx—— 1 mysql mysql 21 Oct 11 01:01 xtrabackup_binlog_pos_innodb
[root@alfamart ~]# innobackupex –host=localhost –user=myuser –password=mypassword –stream=tar ./ | ssh -q root@192.168.0.121 “cat – > /tmp/test/backup.tar”

SERVER A ( 192.168.0.121)
[root@REMASTER63 test]# ls -l /tmp/test/backup.tar

[root@REMASTER63 test]# tar -ixvf backup.tar

[root@REMASTER63 test]# ls -l
total 64868
-rw-r–r– 1 root root 260 Oct 17 22:59 backup-my.cnf
drwxr-xr-x 2 root root 4096 Oct 17 23:18 percona
drwxr-xr-x 2 root root 4096 Oct 17 23:18 percona_addons
drwxr-xr-x 2 root root 4096 Oct 17 23:18 percona_report
-rw-rw—- 1 root root 18874368 Oct 17 22:43 ibdata1
drwxr-xr-x 2 root root 4096 Oct 17 23:18 mysql
drwxr-xr-x 2 root root 4096 Oct 17 23:18 oshop_gc
drwxr-xr-x 2 root root 4096 Oct 17 23:18 performance_schema
-rw-r–r– 1 root root 13 Oct 17 22:59 xtrabackup_binary
-rw-r–r– 1 root root 23 Oct 17 22:59 xtrabackup_binlog_info
-rw-rw—- 1 root root 79 Oct 17 22:59 xtrabackup_checkpoints
-rw-rw—- 1 root root 2560 Oct 17 22:59 xtrabackup_logfile

[root@alfamart mysql]# /etc/init.d/mysql stop

[root@alfamart lib]# mv mysql mysql-percona

[root@alfamart lib]# mkdir mysql

[root@REMASTER63 test]# rsync -avz -e ‘ssh -p 22’ /tmp/test/* root@192.168.0.140:/var/lib/mysql/

[root@alfamart mysql]# chown -R mysql.mysql /var/lib/mysql

[root@alfamart mysql]# /etc/init.d/mysql start
Starting MySQL (Percona Server)…. SUCCESS!

RSYNC EXCLUDE, RSYNC INCLUDE , Single file or Multiple Directory


Rsync adalah tool untuk transfer dan sinkronisasi file atau tree (struktur direktori dan file) secara satu arah, baik transfer lokal (di sistem yang sama) maupun remote (jaringan/internet). Rsync merupakan tools kecil yang powerful karena bisa bertindak sebagai server sekaligus sebagai klien.

Gambar dibawah disetup 2 server A (192.168.0.1) dan B(192.168.0.2). Untuk memudahkan pemahaman tentang  rsync maka dibuat directory crm yang akan di tranfer ke server B.

Untuk tahap pertama yang paling penting adalah serverA harus bisa login ke Server B tanpa password (openssh) via pulic_keynya.

Langkah-langkahnya:

Server A
1. Create key rsa

[root@serverA~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
d7:5f:da:24:d2:0f:95:1b:ad:51:8d:50:3e:fe:b2:3d root@ecentrix6
The key’s randomart image is:
+–[ RSA 2048]—-+
| .o..o|
| …+|
| +oo|
| . o =o|
| S . o *.o|
| . o X |
| + +|
| E |
| . o|
+—————–+

2. Copy id_rsa.pub ke server B
[root@serverA ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.0.2
enter -> masukkan password server B -> Jika password benar maka akan masuk ke shell server B -> exit

3. Coba login ke server B
[root@serverA~]# ssh root@192.168.0.2 -> harusnya tidak meminta password lagi

Gambar di tengah adalah salah satu stuktur dir crm yang ditempatkan pada dir /var/www/html/crm (serverA)

Case 1:

  1. rsync exclude spesific directory
    rsync -avz –exclude ‘config’ /var/www/html/crm/ root@192.168.0.1:/var/www/html/crm/
    (mencopy seluruh dir crm kecuali folder config)
  2. Exclude multiple directory dengan pattern
    rsync -avz –exclude ‘config’  –exclude ‘admin.*’ /var/www/html/crm/ root@192.168.0.1:/var/www/html/crm/
    (mencopy seluruh dir crm kecuali folder config,folder admin.spv dan admin.agent)
  3. Exclude single file or multiple file
    rsync -avz –exclude ‘.jpg’  –exclude ‘init.php’ /var/www/html/crm/ root@192.168.0.1:/var/www/html/crm/
    (mencopy seluruh dir crm kecuali file yang berextension jpg dan file init.php)
  4. Exclude file and directory
    rsync -avz –exclude ‘*.jpg’ –exclude ‘config’ /var/www/html/crm/ root@192.168.0.1:/var/www/html/crm/
    (mencopy seluruh dir crm kecuali file yang berextension jpg dan folder config )
  5. Jika file yang di exclude sangat banyak maka daftarkan pada satu file
    Contoh:

    foder atau file yang akan di copy ke server B kecuali:

    default.php

    init.php
    images

    maka list nama file or dir tersebut di daftarkan di satu file
    [root@serverA]# vim exclude-crm.txt -> masukkan list file diatas -> save
    rsync -avz –exclude-from =’exclude-crm.txt’ /var/www/html/cr/m root@192.168.0.1:/var/www/html/crm/yang perlu diperhatikan adalah option “–exclude-from”

  6. Jika file yang akan di copy hanya beberapa file maka disarankan menggunakan option “–files-from” yang merupakan kebalikan dari “–exclude-from”
    Contoh:
    admin.php
    default.php
    init.php
    a.jgp
    index.php
    lib

    adalah file2 yang akan dicopy ke server B, maka daftarkan name file tersebut satu file
    [root@serverA]# vim include-crm.txt
    rsync -ravz –files-from=include-crm.txt /var/www/html/crm/ root@192.168.0.1:/var/www/html/crm/

Terimakasih

Rsyn Backup –delete-after:)


Pada kesempatan ini akan dijelaskan sinkronisasi backup dengan menggunakan rsync yang di integrasikan dengan openssh. Cara ini saya terapkan di salah satu sistem call center yang merupakan client perusahaan.Cara ini sebenarnya agak sedikit “koyol” tapi apa boleh dikata karena keterbatasan hardware /server. Apila ada beberapa server direkomendasikan  menggunakan HA.  Kenapa saya katakan terbatas karena server hanya ada 2 yaitu 1 server untuk IPBX dan satu untuk server CRM. Untuk database  saya menggunakan replikasi mysql dengan tipe cross aritnya server IPBX replikasi ke server CRM dan database CRM di replikasi ker server IPBX. Masing-masing OS menggunakan Centos 5.5 versi 64 bit.

Direktory yang akan di sinkronisasikan adalah /var/www/html/, semua direktory /var/www/html yang di IPBX akan di backup ke /var/www/html/ server CRM dan sebaliknya.

Berikut adalah implementasinya.

IPBX : 192.168.137.100

CRM : 192.168.137.200

[root@centos5-01 ~]# uname -r
2.6.18-194.el5
[root@centos5-02 ~]# uname -r
2.6.18-194.el5

Generate public key di masing-masing server

[root@centos5-01 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
05:70:56:f6:4c:f2:76:53:1b:85:6e:e5:57:cd:f7:ff root@ipbx

[root@centos5-01 .ssh]# ls -l
total 12
-rw——- 1 root root 1675 Oct  1 12:17 id_rsa
-rw-r–r– 1 root root  391 Oct  1 12:17 id_rsa.pub
-rw-r–r– 1 root root 3154 Sep 25 21:44 known_hosts

[root@centos5-01 .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.137.200
10
root@192.168.137.200’s password:
Now try logging into the machine, with “ssh ‘root@192.168.137.200′”, and check in:

.ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.
Lakukan pengetesan apakah ssh ke server CRM tanpa password
[root@centos5-01 .ssh]# ssh root@192.168.137.200
Last login: Sat Oct  1 11:38:45 2011 from 192.168.137.100

SUKSES

“Lakukan hal yang sama dari server CRM ke server IPBX”

Next

[root@centos5-01 ~]# cd /var/www/html/

root@centos5-01 html]# ls -l
total 2420
drwxr-xr-x 15 cactiuser users    4096 Oct  1 11:43 cacti
drwxr-xr-x 15 root      root     4096 Oct  1 12:24 dahsboard

Direktory yang akan di backup adalah dashboard ke server crm /var/www/html/

Create 1 buah shell script di direktory /usr/bin ( ini terserah anda)

vim rsync-var-www

#!/bin/bash
/usr/bin/rsync -avz –delete-after -e ‘ssh -p 22’ /var/www/html/dashboard/ root@192.168.137.200:/var/www/html/

Option –delete-after digunakan agar isi direktory dashaboard selalu sama dengan isi dir di server “backupnya” tentunya setelah cron dijalankan sesuai dengan parameter yang di set.

Masukkan ke crontab

crontab -e

Tambahkan script di bawah

0 1 * * *  sh /usr/bin/rsync-var-www.sh > /dev/null 2>&1

Backup akan di jalankan setiap hari jam 1 pagi hari (dini hari)

Hal yang sama lakukan dari server CRM ke server IPBX

Demikian tutorial ini dibuat semoga bermanFAAT:)

Thx

 

RSYN BACKUP :)


#!/bin/bash
# "PUSH" RECORDING (VOICELOGGER) to SERVER BACKUP
# -------------------------------------------------------------------------
# Copyright (c) 2011 <moses.spackeu@yahoo.com / mustafa@intelix.co.id>
# -------------------------------------------------------------------------
# Tested under RHEL / CentOS 5.5

FIND="$(which find)"
RSYNC="$(which rsync)"
DATE=$( date +%F )				 				 # format yyyy-mm-dd ex: 2011-30-03
DATE_TIME="$( date +%F)":"$( date +%H:%M:%S)"    # format yyyy-mm-dd ex: 2011-30-03 10:00:00
FORMAT_DIR="$( date +%Y/%m/%d)"			 		 # format yyyy/mm/dd ex: 2011/30/03

SOURCE_IP="10.10.21.23"
BACKUP_IP="10.10.21.24"

SOURCE_DIR="/home/ecentrix/recording/"
BACKUP_DIR="/home/ecentrix/recording/"
LOG_DIR="/home/ecentrix/recording/log/"
CURRENT_LOG="/home/ecentrix/recording/log/rsync-current.log"

PERCENTAGE_ALERT="75"

PARTITION_DIR="/dev/sda5"	# partisi /home

TESTING="Y"

LOG_FILE="${LOG_DIR}recording_$DATE.log"
if [ "$TESTING" == "Y" ]; then
	OPTIONS="-avrn --stats --progress -e"
else
	OPTIONS="-avr --stats --progress -e"
fi

SSH_USER="ecentrix"
SSH_HOST="${BACKUP_IP}"

> $CURRENT_LOG
> $LOG_FILE

REMOTE_IS_LIVE=`ping -s 1 -c 1 $BACKUP_IP > /dev/null; echo $?`
if [ $REMOTE_IS_LIVE -eq 0 ]; then
	SDATE=`date`
	echo "----  Ping server backup ${BACKUP_IP} at $SDATE  ---"  >> $CURRENT_LOG 2>&1
        $RSYNC $OPTIONS 'ssh -p 22' ${SOURCE_DIR} ${SSH_USER}@${SSH_HOST}:${BACKUP_DIR} >> $CURRENT_LOG 2>&1
        RETVAL=$?
        if [ $RETVAL -eq "0" ]; then
                echo "----  Rsync started at `date`  ---"  >> $CURRENT_LOG 2>&1
                echo "----  Rsync completed at `date`  ----" >> $CURRENT_LOG 2>&1
                grep "Rsync started at" $CURRENT_LOG >> $LOG_FILE
                grep "Number of files:" $CURRENT_LOG >> $LOG_FILE
                grep "Number of files transferred:" $CURRENT_LOG >> $LOG_FILE
                grep "Total file size:" $CURRENT_LOG >> $LOG_FILE
                grep "Total transferred file size:" $CURRENT_LOG >> $LOG_FILE
                grep "Total bytes sent:" $CURRENT_LOG >> $LOG_FILE
                grep "Total bytes received:" $CURRENT_LOG >> $LOG_FILE
                grep "Rsync completed at" $CURRENT_LOG >> $LOG_FILE
				df -PH | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
				do
					LEFT_PERCENTAGE=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
					FS_PARTITION=$(echo $output | awk '{ print $2 }' )
					if [ "{$FS_PARTITION}" = "{$PARTITION_DIR}" ]; then 
						if [ "$LEFT_PERCENTAGE" -ge "$PERCENTAGE_ALERT" ]; then
							echo "" >> $LOG_FILE
							#---------------delete backup 7 hari yang lalu----------------------------------------
							DAYS=$(for d in $(seq 7 14);do date --date="$d days ago" +"%Y/%m/%d"; done)
							for d in $DAYS
							do
								if [ "$TESTING" == "N" ]; then
									/bin/rm -rf $SOURCE_DIR$d
								fi
								echo "Delete Dir $SOURCE_DIR$d" >> $LOG_FILE
							done
							#---------------end 7 hari yang lalu-------------------------------------------

						fi
					fi
				done
        else
                echo "----  Rsync Error at `date` ----" >> $CURRENT_LOG 2>&1
                echo "----  Rsync Error at `date` ----" >> $LOG_FILE
                echo "----  Please check the error log ----" >> $LOG_FILE
        fi
else
        echo "---- Ping Server Backup ($BACKUP_IP) : FAIL, Pls Check Backup Server!!!!" >> $CURRENT_LOG 2>&1
fi
shisdew

Listens until think alike

moses.spaceku@yahoo.com / voip ipbx

Hosted PBX, IP-PBX SOHO/ CALL CENTER, VOICE GATEWAY, VOICE CARD, COST EFECTIVE SOLUTIONS (LCR), GSM/CDMA GATEWAY