Setup rsync pada Linux untuk Backup secara Rutin

rsync-backup-590x347

Pada postingan sebelumnya, telah dijelaskan secara sekilas bagaimana melakukan backup menggunakan rsync. Pada artikel kali ini, kita akan melakukan setup rsync untuk melakukan backup setiap jam.

Anggap ada 2 server dengan domain a.com dan b.com. Backup akan dilakukan dari server a.com ke b.com dengan folder yang akan di backup bernama backupfolder . Berikut adalah langkah yang ditempuh untuk melakukan setup.

  • Pada server b.com, buat user baru khusus untuk backup. Misal nama user yang dibuat adalah backupuser
[root@b ~]# adduser backupuser
[root@b ~]# passwd backupuser
Changing password for user backupuser.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
  • Dari server a.com, setting agar dapat login ssh ke server b.com tanpa input password
[root@a ~]# ssh-copy-id backupuser@b.com
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
backupuser@b.com's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'backupuser@b.com'"
and check to make sure that only the key(s) you wanted were added.
  • Buat backup folder dan 100 file kosong untuk uji coba
[root@a ~]# mkdir backupfolder
[root@a ~]# touch backupfolder/file{1..100}
[root@a ~]# ls backupfolder/
file1    file13  file18  file22  file27  file31  file36  file40  file45  file5   file54  file59  file63  file68  file72  file77  file81  file86  file90  file95
file10   file14  file19  file23  file28  file32  file37  file41  file46  file50  file55  file6   file64  file69  file73  file78  file82  file87  file91  file96
file100  file15  file2   file24  file29  file33  file38  file42  file47  file51  file56  file60  file65  file7   file74  file79  file83  file88  file92  file97
file11   file16  file20  file25  file3   file34  file39  file43  file48  file52  file57  file61  file66  file70  file75  file8   file84  file89  file93  file98
file12   file17  file21  file26  file30  file35  file4   file44  file49  file53  file58  file62  file67  file71  file76  file80  file85  file9   file94  file99
  • Cobalah menjalankan 1 perintah rsync, dan pastikan rsync dapat berjalan tanpa input password.
[root@mail ~]# rsync -avzhe ssh backupfolder backupuser@data-old.akhfa.me:~/
sending incremental file list
backupfolder/
backupfolder/file1
backupfolder/file10
backupfolder/file100
backupfolder/file11
backupfolder/file12
backupfolder/file13
backupfolder/file14
backupfolder/file15
backupfolder/file16
backupfolder/file17
backupfolder/file18
backupfolder/file19
backupfolder/file2
backupfolder/file20
backupfolder/file21
backupfolder/file22
backupfolder/file23
backupfolder/file24
backupfolder/file25
backupfolder/file26
backupfolder/file27
backupfolder/file28
backupfolder/file29
backupfolder/file3
backupfolder/file30
backupfolder/file31
backupfolder/file32
backupfolder/file33
backupfolder/file34
backupfolder/file35
backupfolder/file36
backupfolder/file37
backupfolder/file38
backupfolder/file39
backupfolder/file4
backupfolder/file40
backupfolder/file41
backupfolder/file42
backupfolder/file43
backupfolder/file44
backupfolder/file45
backupfolder/file46
backupfolder/file47
backupfolder/file48
backupfolder/file49
backupfolder/file5
backupfolder/file50
backupfolder/file51
backupfolder/file52
backupfolder/file53
backupfolder/file54
backupfolder/file55
backupfolder/file56
backupfolder/file57
backupfolder/file58
backupfolder/file59
backupfolder/file6
backupfolder/file60
backupfolder/file61
backupfolder/file62
backupfolder/file63
backupfolder/file64
backupfolder/file65
backupfolder/file66
backupfolder/file67
backupfolder/file68
backupfolder/file69
backupfolder/file7
backupfolder/file70
backupfolder/file71
backupfolder/file72
backupfolder/file73
backupfolder/file74
backupfolder/file75
backupfolder/file76
backupfolder/file77
backupfolder/file78
backupfolder/file79
backupfolder/file8
backupfolder/file80
backupfolder/file81
backupfolder/file82
backupfolder/file83
backupfolder/file84
backupfolder/file85
backupfolder/file86
backupfolder/file87
backupfolder/file88
backupfolder/file89
backupfolder/file9
backupfolder/file90
backupfolder/file91
backupfolder/file92
backupfolder/file93
backupfolder/file94
backupfolder/file95
backupfolder/file96
backupfolder/file97
backupfolder/file98
backupfolder/file99

sent 4.44K bytes  received 1.92K bytes  4.24K bytes/sec
total size is 0  speedup is 0.00
  • Buka pengaturan cron
crontab -e
  • Masukkan perintah rsync pada cron agar dapat dijalankan setiap jam. Pastikan backupfolder dimasukkan dalam bentuk fullpath. Misalkan ada pada /root/backupfolder
@hourly rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/
  • Pada centos 7, log cron dapat di /var/log/cron
[root@a ~]# cat /var/log/cron | grep rsync
Jul  3 04:00:01 a CROND[9261]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)
Jul  3 05:00:01 a CROND[12278]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)
Jul  3 06:00:01 a CROND[15274]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)
Jul  3 07:00:01 a CROND[18262]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)
Jul  3 08:00:02 a CROND[21261]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)
Jul  3 09:00:01 a CROND[24269]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)
Jul  3 10:00:01 a CROND[27261]: (root) CMD (rsync -avzhe ssh /root/backupfolder backupuser@b.com:~/)

Untuk menggunakan limit bandwidth, gunakan parameter –bwlimit dalam KBps.

Contoh

rsync -avzhe ssh --bwlimit=5000 /root/backupfolder backupuser@b.com:~/

Perintah di atas akan melimit bandwidth yang digunakan oleh rsync menjadi sebesar 5MBps.

[1] [2]

Leave A Comment