Rsnapshot adalah perangkat lunak yang berfungsi mengcopy berkas sistem menggunakan program unix rsync. rsnapshot memudahkan untuk membuat snapshot berkala baik komputer/server lokal,dan bisa juga digunakan secara jarak jauh melalui protokol ssh.
Rsnapshot memanfaatkan tautan keras (hard link) semaksimal mungkin, untuk bisa menghemat ruang hardik yang tersedia di Server backup.

Tergantung pada konfigurasi Anda dan banyaknya hosts yang akan di backup kita bisa mensetup rsnapshot hanya dalam hitungan menit.
Dan file dapat dipulihkan/restore oleh pengguna yang memilikinya, tanpa harus menggunakan akun root.

Konfigurasi sangat simpel dan mudah di fahami, jadi setelah disetting, cadangan Anda dapat berjalan secara otomatis tanpa perlu dijalankan secara manual.
Dikarena rsnapshot hanya menyimpan sejumlah snapshot yang tetap (tetapi dapat dikonfigurasi), jumlah ruang disk yang digunakan tidak akan terus bertambah.

Program rsnapshot dibuat sepenuhnya menggunakan bahasa pemrograman perl tanpa dependensi modul tambahan, dan telah diuji dengan versi 5.004 hingga 5.16.3.
Secara teori rsnapshot dapat dijalankan tanpa ada kendala pada OS UNIX, LINUX, FREEBSD bahkan MAC OS.

INSTALASI RSNAPSHOT DI SERVER BACKUP

Install OS sesuai dengan keinginan masing-masing, disini saya tidak mengharuskan menggunakan distro tertentu, bebas saja anda menggunakan distro linux apapun.
Tapi sebagai contoh saya gunakan centos linux 7, install minimal-system saja karena kita tidak memerlukan GUI semua perintah berbasis command line.

Spesifikasi Server Backup dan Target client backup.
Backup server:
OS : CentOS 7 64 bit minimal system
IP address : 192.168.88.172/24

Client :
OS : Ubuntu Xenial
IP address : 192.168.88.175/24

Terlebih dahulu aktifkan EPEL repository jikalau sebelumnya belum pernah anda aktifkan.


[root]# yum install epel-release

Kemudian install rsync dan rsnapshot.


[root]# yum install rsnapshot rsync

KONFIGURASI CLIENT

Disisi client hanya di butuh program rsync, sshd server untuk dapat berkomunikasi dengan server backup.


[root]# apt install openssh-server rsync

Sedikit perubahan di ssh server dari konfigurasi standar yaitu ssh harus dapat login menggunakan user root dengan cara merubah /etc/ssh/sshd_config menjadi seperti dibawah ini.


# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

Restart service sshd.

[root]# systemctl restart ssh


KONFIGURASI SERVER BACKUP

Persiapkan terlebih dahulu directory tempat kita akan menyimpan backup dari semua host-host yang akan di rsync.
Idealnya untuk direktory backup menggunakan dedicated hardisk yang terpisah dari system centos itu sendiri dan sebisa mungkin gunakan RAID system minimal RAID 1 untuk meminimalisir data lost/corrupted.

Buat directory baru dengan nama BACKUPS di dalam partisi hardisk backup /dev/sdb1.


[root]# mkdir /media/BackupDisk
[root]# mount /dev/sdb1 /media/BackupDisk

Buat user rsnapshot yang akan diberikan tugas untuk menjalankan program rsnapshot secara berkala.


[root]# useradd -m -d /media/BackupDisk/BACKUPS rsnapshot
[root]# chown -R rsnapshot:rsnapshot /media/BackupDisk/BACKUPS

Untuk membackup server secara jarak jauh kita membutuhkan akses ssh tanpa password, untuk itu kita membutuhkan pasangan kunci untuk proses otentikasi ke ssh server di komputer client.
Login ke user rsnapshot melalui terminal dan generate pasangan kunci (key pair).
Jangan mengetikan passphrase ketika diminta cukup tekan ENTER.


[root]# su - rsnapshot
[rsnapshot]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/media/BackupDisk/BACKUPS/.ssh/id_rsa):
Created directory '/media/BackupDisk/BACKUPS/.ssh'.
Enter passphrase (empty for no passphrase): ENTER
Enter same passphrase again: ENTER
Your identification has been saved in /media/BackupDisk/BACKUPS/.ssh/id_rsa.
Your public key has been saved in /media/BackupDisk/BACKUPS/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:f6635ZcKTwj/fDmQQr+R5CP11rLfNQAdYu+1kXvZbqg [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|           o .   |
|          . + . .|
|           . o + |
|           .oo. *|
|        S.. =o+++|
|         .oo.Oo=o|
|          .++.O+*|
|           oB=.*=|
|          .oE*+o+|
+----[SHA256]-----+

Transfer id ssh ke komputer client menggunakan utility ssh-copy-id.
Masuk ke terminal sebagai user rsnapshot dan jalankan perintah copy id.
Pastikan service ssh di komputer client sudah berjalan dan bisa melakukan login ke port 22 ssh service.


[rsnapshot]$ id
uid=1001(rsnapshot) gid=1001(rsnapshot) groups=1001(rsnapshot)

Copy id ssh ke komputer client dan login sebagai root
[rsnapshot]$ ssh-copy-id [email protected]
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/media/BackupDisk/BACKUPS/.ssh/id_rsa.pub"
The authenticity of host '192.168.88.175 (192.168.88.175)' can't be established.
ECDSA key fingerprint is SHA256:vwGgYbwDY5HWaNcWg0PRZ9NQbuv1GvYHGSCKUVq1HQg.
ECDSA key fingerprint is MD5:b6:f6:4d:ed:e0:0f:8e:cc:4e:e9:ef:9e:09:e3:b0:a4.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Permission denied, please try again.
[email protected]'s password:
[[email protected] ~]$ ssh-copy-id [email protected]
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/media/BackupDisk/BACKUPS/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

Test login ke client tanpa mengunakan password


[rsnapshot]$ $ ssh [email protected]
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-143-generic i686)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
New release '18.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Kembali ke terminal backup server.
Kali ini kita akan membackup directory apache yang ada di komputer client berisi konten wordpress dan Joomla cms dalam directory /var/www/html dan akan di simpan di server backup dalam directory /media/BackupDisk/BACKUPS/UBUNTU-XENIAL.
Ubah konfigurasi /etc/rsnapshot.conf tapi terlebih dahulu backup file tersebut.

[root]# cp /etc/rsnapshot.conf etc/rsnapshot.conf.orig

Edit file /etc/rsnapshot.conf. Lakukan perubahan sesuai konfigurasi dibawah ini.
Poin yang harus diperhatikan ketika mengedit berkas rsnapshot.conf adalah SPASI antar argumen HARUS DIUBAH menjadi TAB atau rsnapshot akan error ketika dijalankan.


#################################################
# rsnapshot.conf - rsnapshot configuration file #
#################################################
#                                               #
# PLEASE BE AWARE OF THE FOLLOWING RULE:        #
#                                               #
# This file requires tabs between elements      #
#                                               #
#################################################

....................

###########################
# SNAPSHOT ROOT DIRECTORY #
###########################

# All snapshots will be stored under this root directory.
#
snapshot_root   /media/BackupDisk/BACKUPS

# If no_create_root is enabled, rsnapshot will not automatically create the
# snapshot_root directory. This is particularly useful if you are backing
# up to removable media, such as a FireWire or USB drive.
#
no_create_root  1

....................................

# rsync must be enabled for anything to work. This is the only command that
# must be enabled.
#
cmd_rsync       /usr/bin/rsync

# Uncomment this to enable remote ssh backups over rsync.
#
cmd_ssh /usr/bin/ssh

........................................


#########################################
#     BACKUP LEVELS / INTERVALS         #
# Must be unique and in ascending order #
# e.g. alpha, beta, gamma, etc.         #
#########################################

#retain hourly  6
retain  daily   7
retain  weekly  4
retain  monthly 12

.........................................

###############################
### BACKUP POINTS / SCRIPTS ###
###############################

# LOCALHOST
#backup /home/          localhost/
#backup /etc/           localhost/
#backup /usr/local/     localhost/
#backup /var/log/rsnapshot              localhost/
#backup /etc/passwd     localhost/
#backup /home/foo/My Documents/         localhost/
#backup_script  /usr/local/bin/backup_pgsql.sh  localhost/postgres/
# You must set linux_lvm_* parameters below before using lvm snapshots
#backup lvm://vg0/xen-home/     lvm-vg0/xen-home/

## UBUNTU XENIAL SERVER
backup          [email protected]:/var/www/html/      UBUNTU-XENIAL/

..........................................

Tes konfigurasi rsnapshot.conf apakah sudah benar dan jika benar akan muncul Syntax OK


[rsnapshot]$ rsnapshot configtest
Syntax OK

Kemudian mulai jalankan perintah backup daily

[rsnapshot]$ rsnapshot daily
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/bin/rsnapshot daily
----------------------------------------------------------------------------
ERROR: Could not write lockfile /var/run/rsnapshot.pid: Permission denied

Error diatas artinya user rsnapshot tidak diperkenankan mengakses direktory /var/run untuk itu ubah lokasi PID file ke directory /tmp menjadi:

# If enabled, rsnapshot will write a lockfile to prevent two instances
# from running simultaneously (and messing up the snapshot_root).
# If you enable this, make sure the lockfile directory is not world
# writable. Otherwise anyone can prevent the program from running.
#
lockfile        /tmp/rsnapshot.pid

Jalankan lagi perintah rsnapshot daily, jika tidak ada kendala lagi maka proses backup akan berjalan tunggu beberapa saat sampai proses selesai, setelah itu cek directory di Backup server apakah semua file dan directory /var/www/html sudah tersinkronisasi ke dalam Backup server.

Yang terakhir adalah otomatisasi untuk menjalankan rsnapshot secara berkala baik harian, mingguan dan bulanan.
Caranya dengan memasukan penjadwalan menggunakan crontab
Login di backup server sebagai user rsnapshot kemudian jalankan crontab editor


[rsnapshot]$ crontab -e

40 21 * * *         /usr/bin/rsnapshot daily
20 22 * * 6         /usr/bin/rsnapshot weekly
10 23 1 * *         /usr/bin/rsnapshot monthly

Server Backup sudah siap dan kita hanya tinggal memantau secara berkala direcktori backup untuk memastikan backup berjalan sempurna.
Setelah artikel ini, saya akan lanjutkan dengan tutorial membackup CLIENT WINDOWS menggunakan rsnapshot ke dalam Server Backup.
Semoga bermanfaat.


One thought on “Backup Linux Server File System Menggunakan Rsnapshot.”

Leave a Reply

Your email address will not be published. Required fields are marked *