Wednesday, October 5, 2011

Backup file and databases, Transfer file and schedule on LINUX

Dear Sophen and All Frineds,

1.Command zip  (we can zip it with the extension .zip, .tar.gz .gz ..... and so on..) but I prefer  .tar.gz  in Linux..!!
tar -czPf MyWebsite.zip /path/to/Mywebsite/

2.Backup sql then zip (See in the attached file and edit it...!)
- Use different user instead of "root"
- Specific the Database to Backup  
- Save the bash script below and execute it
 
 
###################################################
#!/bin/bash

# Script Function:
# This bash script backups up the db everyday dependent on when you set the cron job $
# The db will be saved in /public_html/backups/database_backups/
# Db backups older than 15 days will be deleted.

#[Set Backup Path]
DUMP_PATH=/backup/dbbackup

#[Changes Directory]
cd $DUMP_PATH

#[Old DB Deletion Script]
find $DUMP_PATH -name "*.tar.gz" -mtime +15 -exec rm -f {} \;

#[Stamps the file name with a date]
TIMESTAMP=`date +%m-%d-%y-%H%M`

#[DB Backup Scripts]

#################################################################################
#TODO: create backup user with limited privileges and use it instead of root user  or can use other user instead of "root"
#################################################################################

# DB Host
HOST=localhost
# DB Username
USER="root"
# DB Password
PASSWORD="ROOT's_Password"

mysqldump -h$HOST -u$USER -p$PASSWORD --all-databases > mydatabases.sql
tar -czPf $DUMP_PATH/malachi-dump.$TIMESTAMP.tar.gz mydatabases.sql
rm -f mydatabases.sql

###################################################

3.Combine zip site and sql zip to be one zip
- copy your zip site and sql zip into ONE_FOLDER
- then use command zip again (Combine 2zip into 1zip) 

tar -czPf ONE_FOLDER.zip /path/to/ONE_FOLDER

4.For transfer to other Server can be do with (FTP, SSH,...)
- So you need to Extract your zip site by hand
- And also Restore your Database by hand.

5.Edit Crontab using command
crontab -e 

# m  h  dom mon  dow   command

# 30 10 5   10    3   this mean:  (10:30am 5th Oct Wednesday)


////Read More to Understand about Crontab to Run schedule\\\\

MORE INFO: If we have SVN,we can move a Website with Database from one server to other server by using a script. :)


Note!!  In Linux Command if you are not sure or don't know How it Does!!, DON'T USE IT. 
IT CAN MAKE ALL YOUR WEBSITE or DATABASES CRASH...!

ចំនាំ: មិនត្រូវប្រើ LINUX Command ណាដែលអ្នកមិនស្គាល់ច្បាស់ ឫ មិនដឹងថាវាធ្វើអ្វីនោះទេ។
វាអាចធ្វើឲ្យខូចវេបសាយ ឫ កន្លែងផ្ទុកទិន្នន័យរបស់អ្នក!!!!


"Microsoft Give U only Windows, LINUX Give U the Whole HOUSE

Cheers,
Vannak

On Tue, Oct 4, 2011 at 5:15 PM, sophen pho <sophenpho846@gmail.com> wrote:
Dear all,

I am using hosting goddady server linux.
I would like to know how to use command line to back up.
- zip site 
- back up sql then zip
- combine zip site and sql zip to be one zip
- transfer to other sever from goddady server to backup

I am looking forward to hear from you.
Regards,
Sophen

--
Name        : Pho Sophen
School       : Center information Systems and Training
Job            : Junior Developer
Email         : sophenpho846@gmail.com
Facebook   : http://www.facebook.com/sophen.pho
LinkedIn     : http://www.linkedin.com/in/sophenpho
Twitter        : http://twitter.com/pspdeveloper
Skype        : pspdeveloper
Call me      : (855) 97 792 4721
Visit me     : www.sophenkompongchhnang.wordpress.com







--
KEN Vannak
        ken.vannakk@yahoo.com

No comments:

Post a Comment