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 !!

Monday, May 10, 2010

Windows7 bootloader missing from Grub



Recently, I upgraded my Ubuntu from 9.10 to 10.04, I chose to upgrade the grub, and then later I found windows7 bootloader missing from Grub. I tried a few things, trying to recover the bootloader, but ended failed. Whenever I fix windows using Windows Recovery Disc, my windows went back to normal, but unfortunately I lost the Ubuntu's grub. When I tried to recover grub, I lost the windows boot loader.

This is the command to recover grub, by using live-CD (my ubuntu installation is in sda3):
sudo mkdir /media/sda3
sudo mount /dev/sda3 /media/sda3
sudo grub-install --root-directory=/media/sda3 /dev/sda

I tried some other tricks suggested by others to recover bootloader through Windows Recovery Disc (as below),  but this doesn't worked for me. From the repair disk, choose "Command Prompt", then type below command:

bootrec.exe /fixboot
bootrec.exe /fixmbr

 At last, I found a solution here (by Aklem):


1: Run Gparted in Ubuntu

2: Right click on partition with windows, and set flags as "boot"

3. Run windows recovery to fix any other errors using startup repair 
4: Restart

Upon restart, I still can't see Windows7 bootloader in the grub's menu, but when logged in, in Ubuntu, I just run "sudo update-grub" in terminal to update grub, and finally Windows7 bootloader listed in grub.

Yeahaaa, I'm very happy now, problem solved !! :)

Tuesday, March 9, 2010

My root folder corrupted.



A few days ago, I can't boot normally into my ubuntu. I ran sudo fsck, it corrected quite many things. After that, I really can't boot into Ubuntu. I created a thread in Ubuntuforums, trying to get help and the suggested me to just reinstall, since my Home partition is in different partition, and I did it. Yes,  after reinstall, I really can used my files, programs like before. :)

Saturday, January 30, 2010

Ubuntu: 'No init found. Try passing init=bootarg' problem.



Today, I tried to boot into my Ubuntu Karmic Koala, but unfortunately it won't boot. I received these error messages:


-----------------------------------------------------------------
mount: mounting /dev/disk/by-uuid/********************* on /root failed: invalid argument
mount: mounting /sys on /root/sys failed: no such file or directory
mount: mounting /dev on /root/sys failed: no such file or directory
mount: mounting /sys on /root/sys failed: no such file or directory
mount: mounting /proc on /root/proc failed: no such file or directory
Target filesystem doesn't have /sbin/init.
No init fount. Try passing init= bootarg.

BusyBox v1.13.3 (Ubuntu 1:1.13.3-1ubuntu7) built in shell (ash)
Enter 'help' for a list of build in commands

(initramfs)
-----------------------------------------------------------------


The ******* is my UUID no for sda3. What I did was:

Boot into Live-CD, open terminal and run:


sudo fsck /dev/sda3
sudo fsck /dev/sda4
Where my /Root is in sda3, and /Home is in sda4. There was a few issues while fsck checking, and I just press 'Y' for yes, for it to fix the problems. Hehe, maybe today is my lucky day. Normally it takes days to fix Ubuntu's problems. :D

Sunday, January 10, 2010

Letakkan jDownloader pada launcher panel.



Akhirnya, setelah sekian lama menggunakan cara 'biasa' untuk launch jDownloader, akhirnya hari ini dapat juga aku setkan shortcut kat launcher panel dengan jayanya.

* 'biasa' ialah dengan right klik pada fail jDownloader.jar dan pilih 'open with java runtime...'

Apa yang aku lakukan ialah:

tukar ownnership dengan lakukan arahan2 bawah ni pada terminal:

sudo chown -R $USER:$USER /home/username/JDownloader
sudo chmod -R +r /home/username/JDownloader

kemudian, untuk jadikan fail JDownloader.jar executable:

sudo chmod +x /home/username/JDownloader/JDownloader.jar

Untuk bolehkan jDownloader boleh launch dari terminal, lakukan:

sudo touch /usr/local/bin/JDownloader
sudo nano /usr/local/bin/JDownloader

Ini membolehkan fail itu dibuka dan boleh diedit dalam terminal, kemudian paste berikut:

#! /bin/sh
java -jar /home/username/JDownloader/JDownloader.jar

Untuk save dan tutup fail itu, tekan CTRL + X, kemudian Y, dan seterusnya ENTER.


Seterusnya, untuk masukkan jDownloader dalam menu 'Applications', lakukan:

sudo nano /usr/share/applications/JDownloader.desktop


Paste berikut:

[Desktop Entry]
Encoding=UTF-8
Name=JDownloader
Comment=Download Manager
Exec=java -jar /home/username/JDownloader/JDownloader.jar
Icon=/home/username/JDownloader/JDownloader.png
Terminal=false
Type=Application
Categories=GNOME;Network;
StartupNotify=True

Sekarang, JDownloader sudah ada dalam menu, dan boleh juga letakkannya dalam launcher panel dengan klik kanan, dan pilih 'add this launcher to panel'.

Selesai...  :D

* /home/username/JDownloader ialah folder dimana terletaknya fail2 jDownloader.

Thursday, January 7, 2010

Ubuntu 9.10 can't boot.



Hi, recently I received Ubuntu 9.10 CD Desktop Edition. During the install, I deleted all partitions of Ubuntu 9.04 and do fresh install of 9.10. Everything was okay, installed succesfully, but when it comes to reboot, below message appeared:

Common problems:
- Boot args (cat / proc / cmdline)
- Check rootdelay = (did the system wait long enough?)
- Check root = (did the system wait for the right device?)
- Missing modlues (cat / proc / modules; ls / dev)
ALERT! / dev / disk / by-uuid / xxxxxxxxxxxxxxxxxxxxxxxxx does not exists.
Dropping to a shell!

BusyBox v1.13.3 (Ubuntu 1:1.13.3-1ubuntu7) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs)

What I did was:

In the grub menu, press "e" to edit the kernel boot string',

from

recordfail=1
if [ -n ${have_grubenv} ]; then save_env recordfail; fi
set quiet=1
insmod ext2
set root=(hd0,3)
search --no-floppy --fs-uuid --set 1751283b-b905-49fb-bc81-93e2e561bfd9
linux /boot/vmlinuz-2.6.31-14-generic root=UUID=1751283b-b905-49fb-bc81-93e2e561bfd9 ro quiet splash
initrd /boot/initrd.img-2.6.31-14-generic

change to:

recordfail=1
if [ -n ${have_grubenv} ]; then save_env recordfail; fi
set quiet=1
insmod ext2
set root=(hd0,3)
search --no-floppy --fs-uuid --set 1751283b-b905-49fb-bc81-93e2e561bfd9
linux /boot/vmlinuz-2.6.31-14-generic root=UUID=1751283b-b905-49fb-bc81-93e2e561bfd9 ro quiet splash all_generic_ide floppy=off irqpoll pci=nomsi
initrd /boot/initrd.img-2.6.31-14-generic


Then, "ctrl+x" to boot and I can boot into Ubuntu 9.10 happily...


To change that permanently, we have to edit the grub file.


sudo gedit /etc/default/grub

Add the last line, like this:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
GRUB_CMDLINE_LINUX="all_generic_ide floppy=off irqpoll pci=nomsi"

 Then run update-grub2


sudo update-grub2

Wednesday, January 6, 2010

My first post in this Blog.



Yeah, I managed to find time to get this blog created. Well done to me.

I'm trying to write anything, try to write some important notes for me to refer later.


dobbod
Shah Alam