Thursday, April 7, 2011

How To Backup Mysql Database On Server Using Rsync & SSH

How To Backup Mysql Database On Server Using Rsync & SSH

Step :
I.     Make sure you can SSH without password on your server, see this

II.  Test Rsync
    
       If first step done, you can test copy data from server with rsync.
       $ rsync -avz -e ssh remoteuser@remotehost:/remote/dir /this/dir/ 

III. Backup Mysql Server
     
       1. Create New Directoery backup Mysql on Server, etc : /home/user/backupmysql seting permision to 777
     
      2. Use this script my_sql.sh on Server for backup mysql. create on /home/user/         

          Sample Script :



          #!/bin/bash

          # Purpose: Backup mysql

          # Author: Xinix-Technology-Jafar/Habib



          DEST="/home/user/backupmysql/mysql_backup"      #address for temporary folder mysql



          # set mysql login info

          MUSER="root"                                    # Username

          MPASS='PASSWORD'                                # Password

          MHOST="127.0.0.1"                               # Server Name



          # PATH VARIABLES

          MK=/bin/mkdir;                    # Location of the mk bin

          RM=/bin/rm;                    # Location of the rm bin



          # guess binary names

          MYSQL="$(which mysql)"

          MYSQLDUMP="$(which mysqldump)"



          # CREATE MYSQL BACKUP

          # Remove existing backup dir - because we backup the files before onto our backup server, this is safe to do!

          $RM -Rf $DEST

          # Create new backup dir

          $MK $DEST



          # get all db names

          DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"

          for db in $DBS

          do

          FILE=${DEST}/${db}.sql

          $MYSQLDUMP --single-transaction -u $MUSER -h $MHOST -p$MPASS $db > $FILE

          done

     
      3. Run Script 

          $ sh my_sql.sh

      4. If work, script will :
         - Backup all database on your MYSQL
         - Copy backup data to temporary folder ( /mysql_backup )

         *Note :* This script will delete temporary folder and create new temporary folder ( /mysql_backup )
     
IV.  Run Script my_sql.sh & copy backup via SSH

      1. Creat new
backup folder on host & set permision 777, etc:
          $ mkdir /home/user/mysqlserver
        $ mkdir /home/user/mysqlserver/current
        $ mkdir /home/user/mysqlserver/old
        $ chmod 777 -R /home/user/mysqlserver

     
      2. Create Script mysqlserver.sh on /home/user/mysqlserver. Script:
        

         
        #!/bin/bash

         unset PATH



         # USER VARIABLES

         BACKUPDIR=/home/user/mysqlserver                    # Host folder to save backup file

         KEY=/home/user/.ssh/id_dsa                        # SSH key

         MYSQL_BACKUPSCRIPT=/home/user/my_sql.sh                        # Path to the remote mysql backup script

         PRODUCTION_USER=Userserver@Addressserver                        # The user and the address of the production server

         CPDATA=Userserver@Addressserver:/home/user/backup/mysql_backup/    # Folder on the backup server where the backups shall be located

         DAYS=60                                # The number of days after which old backups will be deleted





         # PATH VARIABLES

         SH=/bin/sh                                # Location of the bash bin in the production server!!!!



         CP=/bin/cp;                                # Location of the cp bin

         FIND=/usr/bin/find;                            # Location of the find bin

         ECHO=/bin/echo;                            # Location of the echo bin

         MK=/bin/mkdir;                                # Location of the mk bin

         SSH=/usr/bin/ssh;                            # Location of the ssh bin

         DATE=/bin/date;                            # Location of the date bin

         RM=/bin/rm;                                # Location of the rm bin

         GREP=/bin/grep;                            # Location of the grep bin

         RSYNC=/usr/bin/rsync;                            # Location of the rsync bin

         TOUCH=/bin/touch;                            # Location of the touch bin

  

         CURRENT=$BACKUPDIR/current                                         # Current File Backup

         OLD=$BACKUPDIR/old                                                 # Old File Backup

         

         # CREATING CURRENT DATE / TIME

         NOW=`$DATE '+%Y-%m'-%d_%H:%M`

         NOW=$OLD/$NOW

         $MK $NOW



         # CREATE REMOTE MYSQL BACKUP BY RUNNING THE REMOTE BACKUP SCRIPT

         $SSH -i $KEY $PRODUCTION_USER "$SH $MYSQL_BACKUPSCRIPT"



         # RUN RSYNC INTO CURRENT

         $RSYNC -avz -e $SSH $CPDATA $CURRENT



         #UPDATE THE MTIME TO REFELCT THE SNAPSHOT TIME

         $TOUCH $BACKUPDIR/currentmysqlD



         # MAKE HARDLINK COPY

         $CP -R $CURRENT/* $NOW



         # REMOVE OLD BACKUPS                                              # untuk menghapus secara otomatis file backup yang lama

         for FILE in "$( $FIND $OLD -maxdepth 1 -type d -mtime +$DAYS )"

         do

         #    $RM -Rf $FILE

         #      $ECHO $FILE

         done


      4. Run Script 

          $ sh mysqlserver.sh

      5. If work, Script will execute :
         - Order server to run script backup mysql ( my_sql.sh )
         - Copy data on temporary folder @ server ( /mysql_backup ) using rsync to curent
folder on host ( /home/user/mysqlserver/current )
         - Create new folder with date format on old folder wich inside is all data on current folder



thx to : - Stephan Jau
          - troy.jdmz

SSH Without Password

How To SSH Without Password

Step :

1. Create SSH direktori         $ mkdir -p $HOME/.ssh

2. Permisions
        $ chmod 0700 $HOME/.ssh

3. Create Key Pass id_dsa.pub untuk HostController ( HC )
      
$ ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''
  
4. Add id_dsa.pub ke Server
        - From HC input
         $ cat .ssh/id_dsa.pub | ssh userserver@addresserver 'cat >> .ssh/authorized_keys'
        - Input password Server
        - Set Permision to 600 @ /.ssh/authorized_keys       
        - Test SSH with ssh userserver@addressserver
        - If work, you will login without password
        - If don't work, cek permision on your folder ( /home/ , /home/user/.shh & /home/user/.shh/authorized_keys)

Monday, April 4, 2011

Canon Pixma MP258 or any MP250 series Printer and Scanner on Ubuntu 10.04


If you are using any Debian Based distro like Ubuntu then you need to follow the following steps .
1. Download the driver from Here
2. Open the archieve and there will be two .deb files (cnijfilter-common_3.20-1_i386.deb and cnijfilter-mp250series_3.20-1_i386.deb) , now install them and connect your Printer and print the test page .

if you are using RPM based distro then you need to follow the following steps .
1. Download the drivers from Here
2. Open the archieve and there will be two .rpm files , now install them and connect your Printer and print the test page .

For Arch Linux ( 32bit only)
1. Download PKGBUILD file Here
2. Open the archieve and you will get a folder named “cnijfilter-mp250″ , now open the terminal and cd to that folder and issue the following commands
(a) makepkg -s –asroot
(b) pacman -U filename.pkg (where “filename” is the name of the file that is just created in the “cnijfilter-mp250″ folder with extension .pkg)
Now connect your printer and print the test page

Getting Scanner To Work in Ubuntu

I have noticed that some users are not able to get their scanner to work while the printer is working fine . So i found the solution online and here I am going to share that solution with you guys . All you need to do is just to issue the following commands in the order shown below :

Update : With the new Drivers from Canon There is no need to follow the steps below, just install the new drivers and restart your computer. But if your scanner is not identified even after installing the new drivers then follow the steps below.

1 . Download the scanner drivers for for Ubuntu here .

2. Extract the package by double clicking it and you will find two .deb files (scangearmp-common_1.40-1_i386.deb and scangearmp-mp250series_1.40-1_i386.deb) in it . Just install both the files .

3. Now open your terminal and issue the following command

sudo apt-get install libusb-dev build-essential

4. Now we need to get sane-backened so issue the following commands .

sudo apt-get install git-core
git clone git://git.debian.org/sane/sane-backends.git

completion of this step depends upon the speed of your internet and it may take some time if you are on slow connection so pls be patient

5. The above command will save the sane backend in your home directory with the name sane-backends . So now you need to go to that directory . If you are already in your home directory then issue the following command .

cd sane-backends

6. No we can run the configuration of the package with the following command:

./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var

7. Once the configuration is complete we need to compile the package so issue the following command .

make

This process may take a while to complete .

8. The last step is to install the package so issue the following command :

sudo make install

9. The scanner is now installed, however the permissions still need to be set. To set the permissions we will create a new file that will allow usage of the scanner. In the terminal, open Gedit:

sudo gedit

Once the gedit is open copy paste the following text in it

SUBSYSTEM==”usb”, ENV{DEVTYPE}==”usb_device”, MODE:=”0666″  SUBSYSTEM==”usb_device”,MODE:=”0666″

and save this file in your /etc/udev/rules.d directory with the name 40-scanner-permissions.rules

Your PIXMA MP250 scanner is now installed. You many now start scanning using Xsane scanning-utility .

Note : If you have any problem with the following procedure and you still cant get your printer/scanner to work then ask me for help in the comments I am always ready to help, and you can do me favor by linking this blog to your site and recommending it to your friends .

Note: Canon Now provides drivers for 64Bit Version of Ubuntu also.



original Post from harbhag