Minggu, 03 Agustus 2014

FreeBSD Install and Configure Webmin Web-based Interface ( Control Panel )


by  on JULY 7, 2008 · 
http://www.cyberciti.biz/faq/freebsd-installing-webmin/
Q. How do I install webmin control panel for my FreeBSD server?

A. Webmin is a web-based interface for system administration for Unix including FreeBSD. Using any browser that supports tables and forms, you can setup user accounts, Apache, DNS, file sharing, firewall and so on. Webmin consists of a simple web server, and a number of CGI programs which directly update system files like /etc/inetd.conf and /etc/master.passwd.

Install webmin

To install webmin, update your ports, enter:
# portsnap fetch update
Install webmin from /usr/ports/sysutils/webmin, enter:
# cd /usr/ports/sysutils/webmin
# make install clean

Configure webmin

Now, webmin is installed. Start webmin on startup, enter:
# vi /etc/rc.conf
Append following line:
webmin_enable="YES"
Save and close the file. You need to run /usr/local/lib/webmin/setup.sh script in order to setup the various config files, enter:
# /usr/local/lib/webmin/setup.sh
Sample output:
***********************************************************************
*            Welcome to the Webmin setup script, version 1.420        *
***********************************************************************
Webmin is a web-based interface that allows Unix-like operating
systems and common Unix services to be easily administered.
Installing Webmin in /usr/local/lib/webmin ...
***********************************************************************
Webmin uses separate directories for configuration files and log files.
Unless you want to run multiple versions of Webmin at the same time
you can just accept the defaults.
Log file directory [/var/log/webmin]: [Press Enter]
***********************************************************************
Webmin is written entirely in Perl. Please enter the full path to the
Perl 5 interpreter on your system.
Full path to perl (default /usr/bin/perl):  [Press Enter]
Testing Perl ...
Perl seems to be installed ok
***********************************************************************
Operating system name:    FreeBSD
Operating system version: 7.0
***********************************************************************
Webmin uses its own password protected web server to provide access
to the administration programs. The setup script needs to know :
 - What port to run the web server on. There must not be another
   web server already using this port.
 - The login name required to access the web server.
 - The password required to access the web server.
 - If the webserver should use SSL (if your system supports it).
 - Whether to start webmin at boot time.
Web server port (default 10000):  [Press Enter]
Login name (default admin):  [Press Enter]
Login password: [type password]
Password again:
Use SSL (y/n): y
***********************************************************************
Creating web server config files..
..done
Creating access control file..
..done
Creating start and stop scripts..
..done
Copying config files..
..done
Changing ownership and permissions ..
..done
Running postinstall scripts ..
..done

How do I view webmin?

Fire a webbrowser and enter url:
https://your-domain.com:10000/
OR
https://your-server-ip:10000/
You should see login html form as follows:

(Fig. 01: - Webmin in action under FreeBSD)

Selasa, 08 Juli 2014

RAID1 - Mirroring: GEOM: Modular Disk Transformation Framework

RAID1 - Mirroring

RAID1, or mirroring, is the technique of writing the same data to more than one disk drive. Mirrors are usually used to guard against data loss due to drive failure. Each drive in a mirror contains an identical copy of the data. When an individual drive fails, the mirror continues to work, providing data from the drives that are still functioning. The computer keeps running, and the administrator has time to replace the failed drive without user interruption.
Two common situations are illustrated in these examples. The first creates a mirror out of two new drives and uses it as a replacement for an existing single drive. The second example creates a mirror on a single new drive, copies the old drive's data to it, then inserts the old drive into the mirror. While this procedure is slightly more complicated, it only requires one new drive.
Traditionally, the two drives in a mirror are identical in model and capacity, but gmirror(8) does not require that. Mirrors created with dissimilar drives will have a capacity equal to that of the smallest drive in the mirror. Extra space on larger drives will be unused. Drives inserted into the mirror later must have at least as much capacity as the smallest drive already in the mirror.

Warning:

The mirroring procedures shown here are non-destructive, but as with any major disk
operation, make a full backup first.

Warning:

While dump(8) is used in these procedures to copy file systems, it does not work on
file systems with soft updates journaling. See tunefs(8)for information on detecting and
disabling soft updates journaling.

Metadata Issues

Many disk systems store metadata at the end of each disk. Old metadata should be erased before reusing the disk for a mirror. Most problems are caused by two particular types of leftover metadata: GPT partition tables and old metadata from a previous mirror.
GPT metadata can be erased with gpart(8). This example erases both primary and backup GPT partition tables from disk ada8:
# gpart destroy -F ada8
A disk can be removed from an active mirror and the metadata erased in one step using gmirror(8). Here, the example disk ada8 is removed from the active mirror gm4:
# gmirror remove gm4 ada8
If the mirror is not running, but old mirror metadata is still on the disk, use gmirror clear to remove it:
# gmirror clear ada8
gmirror(8) stores one block of metadata at the end of the disk. Because GPT partition schemes also store metadata at the end of the disk, mirroring entire GPT disks with gmirror(8) is not recommended. MBR partitioning is used here because it only stores a partition table at the start of the disk and does not conflict with the mirror metadata.

Creating a Mirror with Two New Disks

In this example, FreeBSD has already been installed on a single disk, ada0. Two new disks, ada1 and ada2, have been connected to the system. A new mirror will be created on these two disks and used to replace the old single disk.
The geom_mirror.ko kernel module must either be built into the kernel or loaded at boot- or run-time. Manually load the kernel module now:
# gmirror load
Create the mirror with the two new drives:
# gmirror label -v gm0 /dev/ada1 /dev/ada2
gm0 is a user-chosen device name assigned to the new mirror. After the mirror has been started, this device name appears in /dev/mirror/.
MBR and bsdlabel partition tables can now be created on the mirror with gpart(8). This example uses a traditional file system layout, with partitions for /, swap, /var/tmp, and /usr. A single / file system and a swap partition will also work.
Partitions on the mirror do not have to be the same size as those on the existing disk, but they must be large enough to hold all the data already present onada0.
# gpart create -s MBR mirror/gm0
# gpart add -t freebsd -a 4k mirror/gm0
# gpart show mirror/gm0
=>       63  156301423  mirror/gm0  MBR  (74G)
         63         63                    - free -  (31k)
        126  156301299                 1  freebsd  (74G)
  156301425         61                    - free -  (30k)
# gpart create -s BSD mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k -s 2g mirror/gm0s1
# gpart add -t freebsd-swap -a 4k -s 4g mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k -s 2g mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k -s 1g mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k       mirror/gm0s1
# gpart show mirror/gm0s1
=>        0  156301299  mirror/gm0s1  BSD  (74G)
          0          2                      - free -  (1.0k)
          2    4194304                   1  freebsd-ufs  (2.0G)
    4194306    8388608                   2  freebsd-swap  (4.0G)
   12582914    4194304                   4  freebsd-ufs  (2.0G)
   16777218    2097152                   5  freebsd-ufs  (1.0G)
   18874370  137426928                   6  freebsd-ufs  (65G)
  156301298          1                      - free -  (512B)
Make the mirror bootable by installing bootcode in the MBR and bsdlabel and setting the active slice:
# gpart bootcode -b /boot/mbr mirror/gm0
# gpart set -a active -i 1 mirror/gm0
# gpart bootcode -b /boot/boot mirror/gm0s1
Format the file systems on the new mirror, enabling soft-updates.
# newfs -U /dev/mirror/gm0s1a
# newfs -U /dev/mirror/gm0s1d
# newfs -U /dev/mirror/gm0s1e
# newfs -U /dev/mirror/gm0s1f
File systems from the original ada0 disk can now be copied onto the mirror with dump(8) and restore(8).
# mount /dev/mirror/gm0s1a /mnt
# dump -C16 -b64 -0aL -f - / | (cd /mnt && restore -rf -)
# mount /dev/mirror/gm0s1d /mnt/var
# mount /dev/mirror/gm0s1e /mnt/tmp
# mount /dev/mirror/gm0s1f /mnt/usr
# dump -C16 -b64 -0aL -f - /var | (cd /mnt/var && restore -rf -)
# dump -C16 -b64 -0aL -f - /tmp | (cd /mnt/tmp && restore -rf -)
# dump -C16 -b64 -0aL -f - /usr | (cd /mnt/usr && restore -rf -)
Edit /mnt/etc/fstab to point to the new mirror file systems:
# Device  Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0s1a /  ufs rw 1 1
/dev/mirror/gm0s1b none  swap sw 0 0
/dev/mirror/gm0s1d /var  ufs rw 2 2
/dev/mirror/gm0s1e /tmp  ufs rw 2 2
/dev/mirror/gm0s1f /usr  ufs rw 2 2
If the geom_mirror.ko kernel module has not been built into the kernel, /mnt/boot/loader.conf is edited to load the module at boot:
geom_mirror_load="YES"
Reboot the system to test the new mirror and verify that all data has been copied. The BIOS will see the mirror as two individual drives rather than a mirror. Because the drives are identical, it does not matter which is selected to boot.
See Section 19.3.4, “Troubleshooting” if there are problems booting. Powering down and disconnecting the original ada0 disk will allow it to be kept as an offline backup.
In use, the mirror will behave just like the original single drive.

Creating a Mirror with an Existing Drive

In this example, FreeBSD has already been installed on a single disk, ada0. A new disk, ada1, has been connected to the system. A one-disk mirror will be created on the new disk, the existing system copied onto it, and then the old disk will be inserted into the mirror. This slightly complex procedure is required because gmirror needs to put a 512-byte block of metadata at the end of each disk, and the existing ada0 has usually had all of its space already allocated.
Load the geom_mirror.ko kernel module:
# gmirror load
Check the media size of the original disk with diskinfo:
# diskinfo -v ada0 | head -n3
/dev/ada0
 512             # sectorsize
 1000204821504   # mediasize in bytes (931G)
Create a mirror on the new disk. To make certain that the mirror capacity is not any larger than the original ada0 drive, gnop(8) is used to create a fake drive of the exact same size. This drive does not store any data, but is used only to limit the size of the mirror. When gmirror(8) creates the mirror, it will restrict the capacity to the size of gzero.nop, even if the new ada1 drive has more space. Note that the 1000204821504 in the second line is equal to ada0's media size as shown by diskinfo above.
# geom zero load
# gnop create -s 1000204821504 gzero
# gmirror label -v gm0 gzero.nop ada1
# gmirror forget gm0
Since gzero.nop does not store any data, the mirror does not see it as connected. The mirror is told to forget unconnected components, removing references to gzero.nop. The result is a mirror device containing only a single disk, ada1.
After creating gm0, view the partition table on ada0. This output is from a 1 TB drive. If there is some unallocated space at the end of the drive, the contents may be copied directly from ada0 to the new mirror.
However, if the output shows that all of the space on the disk is allocated, as in the following listing, there is no space available for the 512-byte mirror metadata at the end of the disk.
# gpart show ada0
=>        63  1953525105        ada0  MBR  (931G)
          63  1953525105           1  freebsd  [active]  (931G)
In this case, the partition table must be edited to reduce the capacity by one sector on mirror/gm0. The procedure will be explained later.
In either case, partition tables on the primary disk should be first copied using gpart backup and gpart restore.
# gpart backup ada0 > table.ada0
# gpart backup ada0s1 > table.ada0s1
These commands create two files, table.ada0 and table.ada0s1. This example is from a 1 TB drive:
# cat table.ada0
MBR 4
1 freebsd         63 1953525105   [active]
# cat table.ada0s1
BSD 8
1  freebsd-ufs          0    4194304
2 freebsd-swap    4194304   33554432
4  freebsd-ufs   37748736   50331648
5  freebsd-ufs   88080384   41943040
6  freebsd-ufs  130023424  838860800
7  freebsd-ufs  968884224  984640881
If no free space is shown at the end of the disk, the size of both the slice and the last partition must be reduced by one sector. Edit the two files, reducing the size of both the slice and last partition by one. These are the last numbers in each listing.
# cat table.ada0
MBR 4
1 freebsd         63 1953525104   [active]
# cat table.ada0s1
BSD 8
1  freebsd-ufs          0    4194304
2 freebsd-swap    4194304   33554432
4  freebsd-ufs   37748736   50331648
5  freebsd-ufs   88080384   41943040
6  freebsd-ufs  130023424  838860800
7  freebsd-ufs  968884224  984640880
If at least one sector was unallocated at the end of the disk, these two files can be used without modification.
Now restore the partition table into mirror/gm0:
# gpart restore mirror/gm0 < table.ada0
# gpart restore mirror/gm0s1 < table.ada0s1
Check the partition table with gpart show. This example has gm0s1a for /gm0s1d for /vargm0s1e for /usrgm0s1f for /data1, and gm0s1g for /data2.
# gpart show mirror/gm0
=>        63  1953525104  mirror/gm0  MBR  (931G)
          63  1953525042           1  freebsd  [active]  (931G)
  1953525105          62              - free -  (31k)

# gpart show mirror/gm0s1
=>         0  1953525042  mirror/gm0s1  BSD  (931G)
           0     2097152             1  freebsd-ufs  (1.0G)
     2097152    16777216             2  freebsd-swap  (8.0G)
    18874368    41943040             4  freebsd-ufs  (20G)
    60817408    20971520             5  freebsd-ufs  (10G)
    81788928   629145600             6  freebsd-ufs  (300G)
   710934528  1242590514             7  freebsd-ufs  (592G)
  1953525042          63                - free -  (31k)
Both the slice and the last partition must have at least one free block at the end of the disk.
Create file systems on these new partitions. The number of partitions will vary to match the original disk, ada0.
# newfs -U /dev/mirror/gm0s1a
# newfs -U /dev/mirror/gm0s1d
# newfs -U /dev/mirror/gm0s1e
# newfs -U /dev/mirror/gm0s1f
# newfs -U /dev/mirror/gm0s1g
Make the mirror bootable by installing bootcode in the MBR and bsdlabel and setting the active slice:
# gpart bootcode -b /boot/mbr mirror/gm0
# gpart set -a active -i 1 mirror/gm0
# gpart bootcode -b /boot/boot mirror/gm0s1
Adjust /etc/fstab to use the new partitions on the mirror. Back up this file first by copying it to /etc/fstab.orig.
# cp /etc/fstab /etc/fstab.orig
Edit /etc/fstab, replacing /dev/ada0 with mirror/gm0.
# Device  Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0s1a /  ufs rw 1 1
/dev/mirror/gm0s1b none  swap sw 0 0
/dev/mirror/gm0s1d /var  ufs rw 2 2
/dev/mirror/gm0s1e /usr  ufs rw 2 2
/dev/mirror/gm0s1f /data1  ufs rw 2 2
/dev/mirror/gm0s1g /data2  ufs rw 2 2
If the geom_mirror.ko kernel module has not been built into the kernel, edit /boot/loader.conf to load it at boot:
geom_mirror_load="YES"
File systems from the original disk can now be copied onto the mirror with dump(8) and restore(8). Each file system dumped with dump -L will create a snapshot first, which can take some time.
# mount /dev/mirror/gm0s1a /mnt
# dump -C16 -b64 -0aL -f - /    | (cd /mnt && restore -rf -)
# mount /dev/mirror/gm0s1d /mnt/var
# mount /dev/mirror/gm0s1e /mnt/usr
# mount /dev/mirror/gm0s1f /mnt/data1
# mount /dev/mirror/gm0s1g /mnt/data2
# dump -C16 -b64 -0aL -f - /usr | (cd /mnt/usr && restore -rf -)
# dump -C16 -b64 -0aL -f - /var | (cd /mnt/var && restore -rf -)
# dump -C16 -b64 -0aL -f - /data1 | (cd /mnt/data1 && restore -rf -)
# dump -C16 -b64 -0aL -f - /data2 | (cd /mnt/data2 && restore -rf -)
Restart the system, booting from ada1. If everything is working, the system will boot from mirror/gm0, which now contains the same data as ada0 had previously. See Section 19.3.4, “Troubleshooting” if there are problems booting.
At this point, the mirror still consists of only the single ada1 disk.
After booting from mirror/gm0 successfully, the final step is inserting ada0 into the mirror.

Important:

When ada0 is inserted into the mirror, its former contents will be overwritten by data from the mirror. Make certain that mirror/gm0 has the same contents as ada0 before adding ada0 to the mirror. If the contents previously copied by dump(8) and restore(8) are not identical to what was on ada0, revert /etc/fstab to mount the file systems on ada0, reboot, and start the whole procedure again.
# gmirror insert gm0 ada0
GEOM_MIRROR: Device gm0: rebuilding provider ada0
Synchronization between the two disks will start immediately. Use gmirror status to view the progress.
# gmirror status
      Name    Status  Components
mirror/gm0  DEGRADED  ada1 (ACTIVE)
                      ada0 (SYNCHRONIZING, 64%)
After a while, synchronization will finish.
GEOM_MIRROR: Device gm0: rebuilding provider ada0 finished.
# gmirror status
      Name    Status  Components
mirror/gm0  COMPLETE  ada1 (ACTIVE)
                      ada0 (ACTIVE)
mirror/gm0 now consists of the two disks ada0 and ada1, and the contents are automatically synchronized with each other. In use, mirror/gm0 will behave just like the original single drive.

1Troubleshooting

If the system no longer boots, BIOS settings may have to be changed to boot from one of the new mirrored drives. Either mirror drive can be used for booting, as they contain identical data.
If the boot stops with this message, something is wrong with the mirror device:
Mounting from ufs:/dev/mirror/gm0s1a failed with error 19.

Loader variables:
  vfs.root.mountfrom=ufs:/dev/mirror/gm0s1a
  vfs.root.mountfrom.options=rw

Manual root filesystem specification:
  <fstype>:<device> [options]
      Mount <device> using filesystem <fstype>
      and with the specified (optional) option list.

    eg. ufs:/dev/da0s1a
        zfs:tank
        cd9660:/dev/acd0 ro
          (which is equivalent to: mount -t cd9660 -o ro /dev/acd0 /)

  ?               List valid disk boot devices
  .               Yield 1 second (for background tasks)
  <empty line>    Abort manual input

mountroot>
Forgetting to load the geom_mirror.ko module in /boot/loader.conf can cause this problem. To fix it, boot from a FreeBSD 9.0 or later installation media and choose Shell at the first prompt. Then load the mirror module and mount the mirror device:
# gmirror load
# mount /dev/mirror/gm0s1a /mnt
Edit /mnt/boot/loader.conf, adding a line to load the mirror module:
geom_mirror_load="YES"
Save the file and reboot.
Other problems that cause error 19 require more effort to fix. Although the system should boot from ada0, another prompt to select a shell will appear if/etc/fstab is incorrect. Enter ufs:/dev/ada0s1a at the boot loader prompt and press Enter. Undo the edits in /etc/fstab then mount the file systems from the original disk (ada0) instead of the mirror. Reboot the system and try the procedure again.
Enter full pathname of shell or RETURN for /bin/sh:
# cp /etc/fstab.orig /etc/fstab
# reboot

1 Recovering from Disk Failure

The benefit of disk mirroring is that an individual disk can fail without causing the mirror to lose any data. In the above example, if ada0 fails, the mirror will continue to work, providing data from the remaining working drive, ada1.
To replace the failed drive, shut down the system and physically replace the failed drive with a new drive of equal or greater capacity. Manufacturers use somewhat arbitrary values when rating drives in gigabytes, and the only way to really be sure is to compare the total count of sectors shown by diskinfo -v. A drive with larger capacity than the mirror will work, although the extra space on the new drive will not be used.
After the computer is powered back up, the mirror will be running in a degraded mode with only one drive. The mirror is told to forget drives that are not currently connected:
# gmirror forget gm0
Any old metadata should be cleared from the replacement disk using the instructions in Section 19.3.1, “Metadata Issues”. Then the replacement disk,ada4 for this example, is inserted into the mirror:
# gmirror insert gm0 /dev/ada4
Resynchronization begins when the new drive is inserted into the mirror. This process of copying mirror data to a new drive can take a while. Performance of the mirror will be greatly reduced during the copy, so inserting new drives is best done when there is low demand on the computer.
Progress can be monitored with gmirror status, which shows drives that are being synchronized and the percentage of completion. During resynchronization, the status will be DEGRADED, changing to COMPLETE when the process is finished.

Rabu, 25 Juni 2014

Menggunakan rsync

sumber : http://repo.unnes.ac.id/v2/?p=764

Artikel ini memperkenalkan rsync dan sedikit mempromosikan kelebihan-kelebihan dan fitur-fiturnya yang mudah-mudahan akan menarik pembaca untuk lebih banyak menggunakan rsync dalam pekerjaan sehari-hari.

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). Fungsi rsync mirip/identik dengan tool-tool ini: cp, mv, scp, FTP client. Rsync biasanya digabungkan dengan SSH sebagai metode transpor remotenya, walaupun dapat juga disetup untuk menjadi daemon sehingga tidak membutuhkan SSH. Dalam kasus-kasus tertentu rsync juga dapat digunakan menggantikan HTTP client (seperti wget).Untuk apa rsync?

Apa keunggulan rsync?

Irit bandwidth. Jika di sisi penerima, file yang ingin dikirimkan sudah ada, tapi belum tentu sama (misalnya ukurannya lebih kecil/besar atau terdapat perbedaan karena versinya lebih lama), maka rsync dapat melakukan serangkaian pengecekan perbandingan checksum terhadap blok-blok dalam file di kedua sisi, untuk meminimalisasi jumlah data yang harus ditransfer. Algoritma ini disebut algoritma rsync. Bahkan sebetulnya rsync bermula dari sebuah paper yang menjelaskan algoritma ini.
Jadi, misalnya Anda memiliki 2 buah versi file berukuran kurang lebih 100MB di dua tempat, dengan rsync Anda mungkin Anda hanya membutuhkan transfer data sebesar 50MB, 10MB, atau bahkan di bawah 1MB untuk menyamakan kedua buah versi file ini, bergantung pada seberapa mirip kedua file tersebut sebelumnya.
Atau, misalnya Anda sedang mentransfer file besar lalu putus di tengah jalan. Anda dapat jalankan kembali rsync dan rsync akan melanjutkan kembali transfer dari posisi putus dan memastikan hasil akhirnya nanti sama.
Cepat. Rsync cepat salah satunya karena algoritma rsync yang disebutkan di atas. Selain itu rsync dapat melakukan kompresi data saat transfer. Dibandingkan FTP pun rsync lebih cepat karena dapat melakukan pipelining, sementara transfer menggunakan FTP boros koneksi TCP/IP untuk setiap file yang ditransfer. Ini akan semakin kentara untuk tree berisi file kecil-kecil yang jumlahnya banyak (misalnya file-file website yang umumnya berisi banyak file HTML dan gambar), di mana rsync dapat beberapa kali hingga belasan kali lebih cepat dari FTP.
Fleksibel. Rsync tidak hanya bisa mentransfer file tunggal, tapi juga direktori dan tree secara rekursif. Anda bisa memilih untuk menghapus file/direktori yang sudah tidak ada dari sisi pengirim tapi masih ada di sisi penerima. Anda bisa memilih untuk mensinkronisasi juga metadata file seperti permission, kepemilikan, tanggal, ACL, dll. Rsync dapat menangani link simbolik, hardlink, device, dll. Dan ada banyak opsi lainnya, termasuk yang sering juga dijumpai di tool lain seperti tar, cp, dll.

Sintaks dasar

Pada umumnya sintaks-sintaks berikut ini yang paling sering digunakan. Untuk transfer lokal ke lokal:
$ rsync -av -P PATHSUMBER PATHTUJUAN
Untuk transfer lokal ke remote:
$ rsync -e ssh -av -P -z PATHSUMBER USER@HOST:PATHTUJUAN
Untuk transfer remote ke lokal, cukup kebalikan perintah sebelumnya:
$ rsync -e ssh -av -P -z USER@HOST:PATHSUMBER PATHTUJUAN
Opsi -a (archive) adalah untuk mensinkronkan segala sesuatu, termasuk file/direktori secara rekursif dan metadata (seperti tanggal, kepemilikan, permission) dan file-file spesial seperti link simbolik. Umumnya ini yang kita mau, tapi dalam kasus-kasus tertentu di mana Anda tidak ingin rekursif atau tidak ingin mensinkronkan salah satu dari tanggal/kepemilikan/dll, opsi -a dapat dihilangkan dan/atau diganti dengan opsi-opsi lain seperti -r, -g, -o,
Opsi -v (verbose) membuat rsync memperlihatkan ke layar nama-nama file yang sedang ditransfer. Opsi -P membuat rsync lebih verbose lagi, yaitu menampilkan juga progres/persentasi saat sebuah file sedang ditransfer. Jika kita menggunakan rsync dalam skrip noninteraktif, bisa jadi output yang dihasilkan terlalu banyak. Maka dalam kasus tersebut kita dapat menghilangkan opsi -v dan -P.
Opsi -z (compress) membuat rsync mengkompresi data yang ditransfer. Ini menghemat bandwidth. Untuk transfer remote, gunakanlah selalu opsi ini, kecuali jika Anda berada di intranet yang amat cepat bahkan lebih cepat dari bandwidth harddisk (mis: di lingkungan gigabit ethernet).

Akhiran garis miring

Poin berikut ini perlu benar-benar dipahami oleh pengguna rsync karena seringkali menjebak dan membuat bingung. Tidak seperti shell Unix yang pengampun, rsync membedakan keberadaan garis miring penutup dalam spesifikasi path.
Keberadaan garis miring di akhir path sumber berarti menghindari pembentukan level direktori tambahan. Contoh:
$ rsync -av /home/steven/mirrors/debian /backup/
maka hasilnya adalah /backup/debian karena path sumber tidak diakhiri garis miring. Tapi jika kita menambahkan garis miring:
$ rsync -av /home/steven/mirrors/debian/ /backup/
maka isi dari direktori debian-lah yang akan tersalin ke /backup/ (kemungkinan ini bukan hal yang Anda inginkan, karena direktori /backup/ mungkin saja berisi hal-hal lain). Jika Anda ingin mengganti nama debian di path tujuan, maka sintaks berikut ini yang benar:
$ rsync -av /home/steven/mirrors/debian/ /backup/mirror-debian
Sebagai salah satu patokan yang bisa dipakai, jika Anda ingin mengganti nama direktori di tujuan, gunakan akhiran garis miring. Jika tidak, sebaiknya tidak usah gunakan.

Beberapa pertanyaan umum dari pemula

Bagaimana jika transfer putus di tengah-tengah? Tidak masalah. Justru inilah manfaat utama rsync. Rsync akan meneruskan proses sinkronisasi dari titik terakhir sebelum putus. Bahkan Anda dapat sengaja menghentikan dulu perintah rsync yang sedang berjalan (mis: dengan menekan Ctrl-C di shell), lalu melanjutkannya lagi di lain waktu dengan perintah yang sama (mis: dengan menekan tekan panah atas untuk mengambil histori shell, lalu menekan Enter).
Ini juga berarti dalam mentransfer sebuah tree yang berukuran lumayan besar, Anda tidak perlu repot-repot membuat tarball-nya (.tar.gz) dulu, atau bahkan melakukan split agar ukuran file menjadi kecil-kecil. Cara ini hanya memboroskan ruang disk dan waktu. Cukup rsync langsung tree ke tujuan. Jika putus di tengah-tengah, jalankan kembali perintah rsync yang sama, sampai selesai. Rsync dapat melakukan kompresi transfer (opsi -z) sehingga membuat tarball terkompresi (.gz) tidak begitu bermanfaat.
Kenapa rsync diam dulu sebelum menampilkan daftar file yang ditransfer? Kenapa rsync lambat? Kadang saat melakukan transfer file besar yang terputus di tengah-tengah, rsync akan tampak diam dulu. Ini karena rsync sedang membangun ulang file temporer. Ada opsi-opsi seperti --append, --inplace, dan --whole-file untuk mempercepat ini, tapi kelakukan default rsync menggunakan file temporer adalah untuk alasan keselamatan.
Juga, saat melakukan transfer tree besar (tree dengan ribuan file ke atas) rsync akan membutuhkan sejumlah waktu untuk membangun daftar file. Cara kerja rsync memang membangun daftar file lengkap dulu di kedua sisi pengirim dan penerima agar bisa dibandingkan. Kadang jika filenya banyak sekali, misalnya ratusan ribu hingga jutaan, rsync membutuhkan waktu bermenit-menit atau lebih untuk membangun daftar file ini. Opsi -P akan memperlihatkan progres pembangunan daftar file ini, sehingga rsync tidak tampak diam begitu saja.
Kenapa hasilnya salah? Jika hasil transfer berada 1 level lebih dalam dari yang Anda harapkan (tree "terbungkus" satu level direktori lebih dalam dari yang seharusnya) atau sebaliknya 1 level lebih luar dari yang Anda harapkan (file-file/direktori di level teratas tree "meledak" atau "terbuka"), maka Anda mungkin masih belum memahami kelakuan garis miring di akhir path (lihat bagian sebelumnya).
Jika pengecekan checksum MD5 atau SHA1 terhadap hasil transfer ternyata tidak identik untuk file besar (kadang-kadang terjadi, walau amat jarang), maka Anda bisa menambahkan opsi -c (checksum) untuk memperteliti pengecekan kesamaan, walaupun ini berakibat jumlah waktu yang diperlukan bertambah. Umumnya opsi ini tidak diperlukan karena rsync sudah melakukan juga checksum selama transfer, di samping pembandingan tanggal dan ukuran file.

Tips dalam mirroring

Menghapus file yang sudah tidak ada di sumber. Secara default, rsync tidak akan menghapus file di sisi penerima. Misalnya Anda memiliki:
dir/file1
dir/file2
Lalu di-rsync ke tujuan. Kemudian di sisi sumber terjadi perubahan:
dir/file1 dihapus
dir/file2 dimodifikasi
dir/file3 ditambah
maka rsync akan mengirimkan file2 dan file3, tapi tidak akan menghapus file1 yang ada di tujuan.
Dalam mirroring, biasanya kita ingin mirror yang sama persis, dengan kata lain file1 ingin dihapus juga di tujuan. Untuk itu tambahkanlah opsi --del --force. (Sebetulnya ada berbagai pilihan opsi untuk melakukan penghapusan, misalnya --delete-before, --delete-after, tapi sebagai permulaan, Anda cukup menghafal --del --force saja).
Menghindari kecelakaan. Sebagai pengaman, Anda bisa juga menambahkan opsi --max-delete, misalnya --max-delete 1000. Dalam melakukan mirroring dari sebuah sumber remote yang di luar kekuasaan kita, bisa saja di pihak sumber tersebut terjadi perubahan path atau salah konfigurasi sesaat atau reorganisasi sehingga menyebabkan tree sumber menjadi kosong. Tanpa --max-delete, rsync akan dengan senang hati mengosongkan pula mirror Anda sehingga menghapus bergiga-giga file yang dengan susah payah dan mahal didownload. --max-delete akan membatasi jumlah maksimum file yang bisa didelete, sehingga jika tiba-tiba ada kejadian banyak delete seperti ini Anda bisa mendeteksinya dan mengganti sumber mirror lain misalnya.
Atomik. Dalam memaintain mirror yang besar, biasanya proses mirroring bisa memakan waktu yang lama, berjam-jam bahkan berhari-hari dengan keterbatasan bandwidth. Jika mirrornya sedang dipakai juga, maka bisa jadi proses rsync yang lama ini akan menyebabkan isi mirror menjadi tidak konsisten karena "setengah-setengah" (misalnya, untuk mirror Debian, direktori dists/ yang berisi indeks Releases dan Packages sudah terupdate, tapi di pool/-nya belum, menyebabkan proses apt-get yang memanfaatkan mirror kita menjadi gagal). Rsync menyediakan opsi seperti --delay-updates atau --link-dest untuk membantu proses updating lebih atomik. Pembahasan detilnya di luar cakupan artikel ini, silakan lihat manpage rsync.

Tips dalam melakukan backup

Selain opsi -av -P, dalam melakukan backup filesystem biasanya opsi -H dan -A juga berguna. Opsi -H untuk mempertahankan hubungan hardlink (contoh: /usr/bin/sudo dan /usr/bin/sudoedit di Debian adalah hardlink. Hanya ada satu salinan saja untuk kedua file tersebut. Tanpa opsi -H maka saat ditransfer akan menjadi dua salinan, menghabiskan ruang disk.
Opsi -A untuk menyalin juga metadata ACL, berguna jika Anda menggunakan ACL.
Sebuah contoh aplikasi rsync dalam membuat backup harian dengan histori backup akan dibahas dalam kesempatan lain.

Berbagai tips lainnya

Selektif. Rsync menyediakan berbagai cara yang sangat fleksibel agar kita dapat memilih-milih file mana yang ingin disinkronkan dan mana yang ingin diabaikan (exclude). Beberapa contoh:
Jangan ikut sertakan file-file backup:
$ rsync -av --exclude '*~' --exclude '*.bak' SUMBER TUJUAN
Jangan ikut sertakan direktori metadata .svn (berguna untuk mentransfer direktori source code dari direktori kerja langsung):
$ rsync -av --exclude '.svn' SUMBER TUJUAN
Jika kita menyebutkan path absolut di --exclude, maka itu akan berarti posisinya relatif terhadap SUMBER. Keberadaan garis miring di akhir SUMBER akan lagi-lagi menentukan apakah titik awal yang dianggap akar (root) adalah selevel dengan SUMBER atau satu level di dalam SUMBER. Contoh:
$ rsync -av --exclude '/.*' /home/steven/ /backup/steven/
Perintah di atas akan membackup direktori home saya, tapi tanpa mengikutsertakan "dotfiles" yang ada tepat di bawah home (umumnya berisi file konfigurasi). Tapi seandainya ada dotfiles di bawah direktori lain, misalnya, /home/steven/proj1/.config maka file tersebut tidak akan di-exclude karena kita hanya menginstruksikan meng-exclude dotfiles yang berada di "root" (/.*).
Opsi --exclude dan pasangannya --include dapat disebutkan berselingan dan berulang kali. Terdapat pula opsi --filter yang lebih fleksibel lagi. Terdapat juga opsi --delete-excluded untuk menghapus file-file yang diexclude di sisi tujuan. Berguna misalnya untuk menghapus file-file backup (*~, *.bak) yang mungkin berserakan di sisi tujuan.
Sebuah contoh yang agak lengkap, dari potongan skrip backup yang pernah saya gunakan untuk membackup direktori home saya. Untuk mengirit waktu dan ruang disk, saya meng-exclude berbagai "sampah" seperti cache browser, trash, direktori temporer, file-file backup, dll. Anda mungkin bisa mengembangkan sendiri opsi favorit Anda.
$ nice -n19 \
  rsync -av --del --force --delete-excluded \
    --exclude '*~' --exclude '*.bak' \
    --exclude '*/cache*' --exclude '*/Cache*' \
    --exclude '*/Trash' --exclude */tmp' \
    /home/steven /backup/
Batasi bandwidth. Rsync dapat diinstruksikan untuk hanya menggunakan bandwidth tidak lebih dari yang kita spesifikasikan. Berguna jika rumah atau kantor kita memiliki bandwidth internet yang terbatas dan tidak ingin proses mirroring regular mengganggu aktivitas lainnya. Tambahkan opsi --bwlimit K, di mana K adalah angka dalam KB/s (kilobyte per detik).
Hemat CPU. Untuk mempercepat dan mengirit resource CPU dalam transfer remote, gunakan opsi -e "ssh -c arcfour" atau -e "ssh -c blowfish" sebagai pengganti opsi -e ssh. Cipher default ssh adalah 3des, dan ini lebih lambat daripada blowfish atau arcfour, sehingga kadang menghabiskan terlalu banyak CPU dan mengakibatkan transfer tidak bisa memanfaatkan kecepatan penuh fast ethernet (100Mbps).
Mengirit bandwidth lebih lagi. Opsi --fuzzy membuat rsync berusaha mencari file di sisi penerima yang mungkin dulunya adalah file yang ingin ditransfer, dari kemiripan ukuran dan/atau nama. Misalnya, jika terjadi perubahan penamaan file, maka tanpa opsi --fuzzy ini rsync akan mentransfer ulang file secara keseluruhan, karena tidak ditemukan file sebelumnya dengan nama yang sama di sisi penerima. Opsi-opsi lain seperti --compare-dest (bisa disebutkan berulang kali), --copy-dest, --link-dest juga berhubungan dengan pengiritan bandwidth dengan berusaha mencari kemiripan/file sumber di sisi penerima jika ada.
Coba-coba dulu. Opsi --list-only akan membuat rsync hanya menampilkan daftar file yang akan diproses. Atau gunakan opsi -n (--dry-run) untuk proses simulasi, mencoba-coba dulu tanpa benar-benar melakukan transfer dan penghapusan. Berguna jika Anda pemula atau jika mencoba kombinasi opsi baru. Siapa tahu pilihan opsi Anda tidak tepat dan Anda justru menghapus atau mengkopi file ke tujuan yang salah! Opsi -i (--itemize-changes) dapat dikombinasikan dengan -n untuk melihat perubahan apa saja yang akan dilakukan pada file. Arti simbol-simbol pada output -i ini dapat dilihat di manpage rsync.

Keterbatasan rsync

Meskipun merupakan swiss-army knife dalam urusan transfer dan sinkronisasi tree, namun rsync tidaklah sempurna. Dua kelemahan utama rsync adalah sifat sinkronisasi yang 1 arah dan lambat jika ukuran tree sudah terlalu besar.
Hanya 1 arah. Sinkronisasi rsync hanya bersifat satu arah, dari pengirim (P1) ke penerima (P2). Jika misalnya baik tree di P1 maupun di P2 berubah secara independen oleh pihak ketiga, lalu P1 dan P2 ingin bertukar perubahan secara 2 arah, maka rsync tidak dapat digunakan. Ada opsi -u untuk melewati file-file di P2 yang lebih baru daripada P1, Anda bisa menggunakan opsi ini pada kasus-kasus tertentu, tapi secara umum, untuk melakukan sinkronisasi 2 arah, sebaiknya digunakan tool lain seperti unison (atau mungkin Anda butuh tool version control seperti subversion atau git).
Lambat untuk tree superbesar. Cara kerja rsync adalah dengan mula-mula membangun daftar file lengkap baik di sisi pengirim maupun penerima untuk kemudian dibandingkan. Untuk tree yang sudah amat besar proses ini akan memakan waktu dan juga memori amat besar. Misalnya direktori backup lokal di beberapa server shared hosting di tempat kerja saya yang isinya lebih dari 20 juta file, karena berisi histori backup menggunakan hardlink. Meng-rsync tree ini sekaligus membuat proses rsync memakan memori lebih dari 2-3GB untuk menyusun daftar file, sehingga menghabiskan memori dan mengganggu proses lain.
Kebutuhan memori dalam pembangunan daftar file lengkap di awal proses rsync ini juga membuat para penyedia situs mirror agak enggan menyediakan layanan via rsync. Atau setidaknya membatasi jumlah koneksi simultan rsync, misalnya hanya 1-5.
Diharapkan revisi program dan/atau algoritma rsync berikutnya dapat membuat inovasi dalam hal sinkronisasi tree superbesar, misalnya dengan membentuk daftar file secara paralel atau sambil jalan.

Kamis, 19 Juni 2014

How to upgrade FreeBSD 8.2 to FreeBSD 9.0 with Virtio

Step 1: The upgrade

Let’s get right to it. Here’s the first step in the upgrade process:
freebsd-update upgrade -r 9.0-RELEASE
Once all files have been fetched, you will be asked a number of questions about merging config-files. They all seemed reasonable to me, so I just answered ‘y’ to all of them, but it might differ for you. Make sure you read the diff before accepting it.
If you get the following error:
The update metadata is correctly signed, but failed an integrity check.
Cowardly refusing to proceed any further.
Then simply patch your freebsd-update using the following command (source):
sed -i '' -e 's/=_/=%@_/' /usr/sbin/freebsd-update
and then re-run the upgrade command again.
If that went fine, it’s time to update the actual system. To do that, run:
freebsd-update install
Onde the update is done, reboot your system:
shutdown -r now
When it comes back up, make sure you run the install-again to install again to intall the userland updates:
freebsd-update install
Once you’ve run this, you’ll get the message:
Completing this upgrade requires removing old shared object files.

Please rebuild all installed 3rd party software (e.g., programs
installed from the ports tree) and then run 
"/usr/sbin/freebsd-update install"  again to 
finish installing updates.
This is of course a massive pain in the butt, but you need to do this nonetheless. Depending on how many packages from ports you have installed, this may take everything from a few minutes to a long time.
The easiest way to do this is to run portupgrade (if you don’t have portupgrade, install it from ‘sysutils/portupgrade’):
rm /var/db/pkg/pkgdb.db && pkgdb -Ffuv && portupgrade -afp
I added the ‘p’-flag, as this allows you to run ‘portupgrade -afP’ on other nodes (assuming you have a shared ports-tree) and just install the packages without having to re-compile them.
Finally, when you’ve done this, you can run (for the last time):
freebsd-update install

Step 2: Installing Virtio

Nowadays, Virtio is available in ports. That’s of course great, as that reduces the burdan of installing it. All you need to do is to run:
cd /usr/ports/emulators/virtio-kmod && make clean install
Once the kernel-module is installed, add the following to /boot/loader.conf:
virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
if_vtnet_load="YES"
virtio_balloon_load="YES"
Next, we need to tell the system to actually use Virtio. The above commands assume that you are using ‘emX’ as your network-interface and /dev/daX or /dev/adX as your harddrive. It also that you’re using /etc/pf.conf as your firewall config, and that you have coded it to use the NIC’s name and not just IP-address. If you’re not using PF or use a different setup, simply skip the last command.
cp /etc/fstab /etc/fstab.bak && cat /etc/fstab.bak | perl -pe "s/ad/vtbd/g; s/da/vtbd/g;" > /etc/fstab
cp /etc/rc.conf /etc/rc.conf.bak && cat /etc/rc.conf.bak | perl -pe "s/em/vtnet/g;" > /etc/rc.conf
cp /etc/pf.conf /etc/pf.conf.bak && cat /etc/pf.conf.bak | perl -pe "s/em/vtnet/g;" > /etc/pf.conf
Now power off the system to make the changes to the host:
shutdown -p now
When the system stops, update all network drivers to Virtio and change the primary disk to block-driver.
You should now be able to boot into the new system with Virtio and enjoy a lot better (and more reliable) speed.

source: http://viktorpetersson.com/2012/01/16/how-to-upgrade-freebsd-8-2-to-freebsd-9-0-with-virtio/