Pages

Saturday, October 9, 2010

Tutorial utk auto backup guna rsync, bash dan cron



Aku buat satu tutorial hari ni. Sejak kehilangan data ketika Western Digital HDD 640 GB aku rosak, aku terus mencari satu cara utk backup data2 penting aku ke tempat lain. Akhirnya setelah mencuba beberapa cara, rsync dapat memenuhi apa yang aku inginkan. Aku ingin buat backup fail2 penting dari folder dalam Home (HDD1) aku ke HDD2. Begini caranya, untuk backup folder Documents (dalam partition Home, HDD1) aku ke folder Backup1 (dalam HDD2), ini arahan yang aku lakukan dalam terminal:

sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Documents /media/Backup1/Backup

di mana:
-av, 'a' bermaksud arkib (menyalin semua data termasuk keizinan, masa dll). 'v' bermaksud 'verbose' di mana kita boleh tahu apa yang dijalankan, baik di terminal atau pun di dalam fail log.
--delete, menyemak perubahan antara sumber dan destinasi (ia akan delete fail pd destinasi jika fail yang sama pd sumber sudah di delete)
--log-file=/media/Home/auaa/Documents/Rsync_Logs ialah folder di mana fail log akan disimpan.
$(date +%Y%m%d)_rsync.log ialah nama fail log itu nanti, siap dengan tarikh sekali.
/media/Home/auaa/Documents adalah sumber
/media/Backup1/Backup adalah destinasi

Kita masih boleh terus melakukan arahan yang sama di terminal berulang kali..., atau untuk menyenangkan lagi diri (hehe  :D ), mari buat satu bash skrip dengan cara bawah ni. Buka apa juga teks editor kegemaran korang (aku gunakan Gedit dalam Linux Mint), salin dan tampal arahan rsync tadi macam ni:

#!/bin/bash
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Documents /media/Backup1/Backup

Simpan kat Desktop dengan menamakan fail tersebut sebagai Backup_Skrip.sh (contoh) dan jadikan ia executable dengan jalankan arahan berikut di terminal:

sudo chmod +x /home/your-username/Desktop/Backup_Skrip.sh
Gantikan 'your-username' dengan username korang, atau dengan klik kanan fail Backup_Skrip.sh itu, pilih Properties, Permissions dan kemudian tick pada kotak execute.

Kemudian, korang boleh klik dua kali fail Backup_Skrip.sh tersebut, dan arahan yang terkandung di dalamnya akan dijalankan di terminal (korang kena masukkan password) atau boleh juga gunakan cron utk lakukannya secara automatik. Begini caranya:

Salin fail Backup_Skrip.sh itu ke /root dengan menaip:
sudo cp /home/your-username/Desktop/Backup_Skrip.sh /root

kemudian taip: sudo crontab -e

korang akan nampak dalam terminal:
# m h  dom mon dow   command

di bawahnya, sila taip:
0 22 * * * /root/Backup_Skrip.sh


yang bermaksud (dari kiri ke kanan):
1. Jumlah minit selepas jam (0 hingga 59)
2. Satu jam dalam masa tentera (24 jam) format (0 hingga 23)
3. Hari bulan (1 hingga 31)
4. Bulan (1 hingga 12)
5. Hari dalam minggu (0 adalah Isnin, 7 adalah Ahad)
6. Perintah (command) yang perlu dijalankan

Jadi pada pukul 22:00 (10:00 malam) setiap hari, root akan menjalankan script tersebut, tanpa password sudo (kerana memang dijalankan sebagai root).

Sekarang tekan Control-X, kemudian "Y", kemudian tekan Enter.

Anda akan dapt lihat: 'crontab: installing new crontab'

Dan.... selesai!



Nota: boleh juga gantikan masa, tarikh, hari tersebut dengan:

@reboot     Run once, at startup
@yearly     Run once  a year     "0 0 1 1 *"
@annually   (same as  @yearly)
@monthly    Run once  a month    "0 0 1 * *"
@weekly     Run once  a week     "0 0 * * 0"
@daily      Run once  a day      "0 0 * * *"
@midnight   (same as  @daily)
@hourly     Run once  an hour    "0 * * * *

Aku guna camni (backup akan dijalankan setiap hari, jam 12.00 tengah malam):
@daily /root/Backup_Skrip.sh


Jadi sekarang korang dah tahu bagaimana nak backup fail2 penting korang secara automatik. Itu adalah contoh utk folder Documents dalam Home, boleh juga lakukan perkara yang sama pada folder2 lain. Aku buat camni:

#!/bin/bash
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Documents /media/Backup1/Backup
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Digicam /media/Backup1/Backup
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Misc /media/Backup1/Backup
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Music /media/Backup1/Backup
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Pictures /media/Backup1/Backup
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Videos /media/Backup1/Backup
sudo rsync -av --progress --delete --log-file=/media/Home/auaa/Documents/Rsync_Logs/$(date +%Y%m%d)_rsync.log /media/Home/auaa/Downloads /media/Backup1/Backup


Selamat mencuba !  ;)

My Linux Mint and Windows7 got problem



I'm not sure where the problem came from but recently I'm having problem in using both of my Mint and Windows7. I can't also access my 3rd Hard drive, 1 TB which contain my backup copies of all the important files.

In Mint, the processor seems busy handling something from the moment I logged on to Windows until now, it's been 10 minutes ! I suspected the problem is coming from my 3rd HDD.

I'm scheduling a backup using rsync everyday, my Mint will automatically backup the important folders set from Home to HDD2 and HDD3. Not sure what is wrong, the loading time now is more than the normal.

If I unplugged the HDD3, everything seems okay....

Wednesday, June 30, 2010

POST boot delay



Recently, I reinstalled Linux Mint 9 after previous installation got corrupted. Since then, it really takes time from the POST screen to boot, it takes about 20 seconds. I'm getting more stresses when it also takes time before I can see the desktop after the login page. The error message said that Power Management in running, but luckily I can click on the "Cancel" or the "Logout Anyway" buttons.

After a few search, I found out it suppose to be because of the usb device connected to my computer. Later on, I unplugged my usb bluetooth, and then start the computer. Wow, the 2 problems above solved. Yeehaa !! :)

I didn't tried to plug back the usb bluetooth, but I'll try that later.

Monday, June 28, 2010

Can't boot into Windows7 after deleted primary partition.




Recently, I installed another OS (Linux Mint). Before installing this Mint, I deleted primary partition (sda1) and created entended partition from the earlier primary partition sda1. Since that, I cannot boot into my Windows7 anymore (received error message something like "no bootable device insert boot disk and press any key"), but I've no problem in booting into both Linux Ubuntu and Mint.

I've tried a few things, but seems like the luck is not with me. Below are the things that I've tried:

1. Boot Recovery Disc Windows7 and done the Repair Startup many times (more than 5 times), still no luck.

2. Boot Recovery Disc Windows7 and chose Command Prompt to use:
Bootrec /scanos - The Windows is listed.
Bootrec /fixboot - No element found,
Bootrec /fixmbr - Completed succesfully.

3. Boot Recovery Disc Windows7 and chose Command Prompt to use Diskpart, everything seems okay for the list disk, select disk, list partiton, select partion, except the "active" command. I've been prompted with something like "Virtual Disk Service Error: the specified partition type is not valid for this operation".

I've installed back grub for me to log in into Linux Ubuntu/Mint. From Linux Gparted, I can see this windows partition is flagged as boot.

Here is the solution:

Using Gparted I can't create primary partition from the unallocated partition inside extended partition. I can only created another primary partition by shrunk my sda4 partition (last partition in Gparted) and use the 'just unallocated partition' as the primary partition for the 200 MB partition required.


1. Use Gparted to make an ntfs primary partition. Mark it Active (right click and Flag On)
2. Boot 7 dvd go to command prompt, type diskpart, lis vol, select the new primary with sel vol, ass ( to assign next available drive letter). Exi ( to leave diskpart).
3. bcdboot <7volumeletter>:\windows /s :
4. bootsect /nt60 : /mbr

Yeah at last, I managed to boot into windows7. I also reinstalled Grub, using Linux Mint Live-CD. Everything seems okay just that I can't see Windows bootloader upon start although I can see it is listed when I've done the 'sudo update-grub'. I edited file 'grub.cfg' manually, changed the (hd0,1) to (hd0,7) in Windows7 menuentry (my Windows installation is in sda7). I then run again 'sudo update-grub' and restart, this time Windows bootloader really listed in Linux Mint's grub. Hooray !!

I posted this problem in sevenforums.com.

Tuesday, May 18, 2010

Cannot access Gmail & YahooMail on Ubuntu 10.04



Earlier, I cannot check my emails through Gmail and YahooMail. I tried a few things, but still this issue didn't solved. Today, I googled again, trying to find some other clues, and yes... I managed to get this issues solved.

I can now check my emails on Gmail and YahooMail, and I can also logged in into Facebook. Just before all this things happened, I read somewhere, that someone suggested to disable all Firefox's addons installed, and then test to enable one by one those addons back. I really did it. I finished tested all those addons, all enabled as earlier, and the best thing is I can still check my emails. Emm... don't know what happened.

To confirm everything is okay, I restarted my PC, and still I can logged in happily to those 3 websites. :)


Hooray !!