Tampilkan postingan dengan label database. Tampilkan semua postingan
Tampilkan postingan dengan label database. Tampilkan semua postingan

Kamis, Juli 01, 2010

MySQL : Merge two tables

using phpMyAdmin :

  1. select database
  2. create new table (note that the new table should have the same structure as the table that we want to merge)
  3. go to the SQL menu and type in the sql box :

    INSERT IGNORE
    INTO table_1
    SELECT *
    FROM table_2
    ;
















    doh !

Minggu, Juni 15, 2008

Tutorial Auto Backup Database on Linux Server

Yesterday I and my wife went to RSUD Karanganyar to install and create auto backup database on Linux server.
I use Mandriva 2008 as an OS because it's easy to install.

After success installation, I created script to crontab every hour.
Here is my script, of course it's not my own script.

Ok, coffee and smoking mode on


Once again, this is not my own script, I modified from here.


1. Type this command in shell :


bash$ echo your_host:5432:your_user:your_db:your_pass > ~/.pgpass
bash$ chmod 600 ~/.pgpass


2. Create backup.sh in directory /backup and name it as backup.sh
:

#!/bin/sh
/usr/bin/pg_dump -D -U qwe simrs --no-owner > /backup/simrs.sql
cd /
cd /backup
tar --overwrite --remove-files -czf /backup/simrs-`date '+%Y-%m-%d'`.tar.gz -R *.sql
chmod ugo+r -R *
cp -f *.* /var/www/html/backup
cp -f *.* /mnt/win_d/backup


3. Edit /etc/crontab and add bold line in crontab file :


SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly
01 * * * * root /backup/backup.sh #<-- add this line
02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily
22 4 * * 0 root nice -n 19 run-parts --report /etc/cron.weekly
42 4 1 * * root nice -n 19 run-parts --report /etc/cron.monthly


4. run crontab as root

root@server:~# crontab -u root /etc/crontab


5. check one hour later, or just type :

root@server:~# crontab


After I check /backup directory there is new file simrs-data.tar.gz
I check again at /var/www/html/backup directory, there is also new file simrs-date.tar.gz
I double check again at /mnt/win_d/backup directory, well... it's succeeded

Thanks to open source community :)