System Backup

From Kb_JMY(晉明夷)

Jump to: navigation, search

Contents

Cron Job Commands


Cron Job Commands are actually scheduled Linux Shell commands as provided by many web admin control panels, like cpanel, directadmin, plesk control...


Making symbolic links <-- Not Permitted!

  • Ref: SiteGnd Support TicketID: 167188, 2007-03-01 12:54am
  • Symbolic links Not Permitted! -- the IDS system installed on the SiteGnd server will prevent it from executing such a command.
Further more, the Apache web server is not configured to follow sym links and thus even if you create them, the link won't be working.
  • command format: ln -s source_files destination_directory;


cpanel

  • File Linking Example: ln -s /home/mysite/public_html/en/* /home/mysite/public_html/zh;
->The shell command makes symbolic links (just like making shortcuts in Microsoft Windows) of all files of "public_html/en" to "public_html/zh"


  • Folder Linking Example: ln -s ~/domains/mysite.org/public_html/mFiles/lbx/images/ ~/domains/mysite.org/public_html/lbx/
-> this command make links of the folder "public_html/mFiles/lbx/images" to "public_html/lbx/"

DirectAdmin

  • Ref:
  1. DirectAdmin.com -- Cron Job and log file copy help
  2. DirectAdmin.com -- How to configure multiple backup repositories with the Reseller (or Admin) Level Backup
  • e.g.ln -s /home/myacct/domains/mysite.org/public_html/kb/* /home/myacct/domains/mysite.org/public_html/lx;

Copying Files & Directory

  • Ref: SiteGnd Support TicketID:169364, 2007-03-06 09:18am
  • e.g.
  1. cp ~/_bkup/file1.zip ~/public_html/_bkup -- copying a file
  2. cp ~/_bkup/*.zip ~/public_html/_bkup ------- copying files with *.zip extension
  3. cp -R ~/_bkup/dir1 ~/public_html/_bkup ---- copying a directory
-> copy the file, file1.zip from the directory: ~/_bkup/, to the directory: ~/public_html/_bkup
-> This command can be stored in a file named, "cron.sh", and put it in the home directory, ~/
-> Then the cron job command becomes: /bin/sh ~/cron.sh


Compressing Directories

Compressing 2 or more directories

  • Ref: SiteGnd Support TicketID: 165505 /2007-02-25 09:27pm
  • cd ~/public_html; /bin/tar -cif backup.tar.gz d1 d2 d3; <--- double check if it compress sub-directories too!
-> This Cron Job Command compress the three directories, d1, d2, &d3, under "public_html" into a single file, backup.tar.gz, or
  • cd ~/public_html; /usr/bin/zip -r backup.zip d1 d2 d3 <-- double check if zip support multiple directories

Making *.zip (& unzip)

  • Ref: SiteGnd Support Ticket ID: 164438, Issue Date: 2007-02-22 09:55pm
  • Syntext: /usr/bin/zip -1 /path/to/desired/archive /path/to/the/file
 : /usr/bin/zip - 1 -r destination source
  • e.g. File Compression: cd ~/public_html; /usr/bin/zip -1 ~/_bkup/arch.zip file.txt;
-> compress the file "file.txt" in "~/public_html" (i.e. /home/mysite/public_html/) to "arch.zip" and put it in "~/_bkup/" (i.e. /home/mysite/_bkup/)
  • e.g. Directory Compression: cd ~/public_html; /usr/bin/zip - 1 -r ~/_bkup/mac.zip mac/*;
-> compress the directory "mac" in "~/public_html" (i.e. /home/mysite/public_html/) to "mac.zip" and put it in "~/_bkup/" (i.e. /home/mysite/_bkup/)


  • e.g. unzipping file: cd /home/yogapd/domains/mysite.org/_prg/phpBB; unzip phpBB-3.0.1.zip

Making *.tar

"tar -cf" (no compression)
  • Syntext: tar -cf filename.tar SrcDir;
  • create the file "filename.tar" from the directory "SrcDir" including all files under it;
  • [remarks: c=create, f=file]
  • Examples:
  • cd ~/public_html; /bin/tar -cf ~/_bkup/martclub_mac.tar mac;
  • cd ~/public_html; /bin/tar -cf ~/_bkup/martclub_gallery.tar gallery;
  • cd ~/public_html; /bin/tar -cf ~/_bkup/_Files.tar _Files;
"tar -cvf" (with compression)
  • Examples:
  • cd ~/public_html; /bin/tar -cvf ~/_bkup/martclub_gallery.tar gallery;


System Backup using cpanel

Backup a directory

  1. Directroy to be backed up: /home/mosct/public_html/jmla
  2. Save it to the directroy: /home/mosct/_bkup/mosct.com/
  3. as a compressed file: jmla.tar.gz
  4. Cron Job command:
  • /usr/local/cpanel/bin/cpuwatch 7.0 tar cipzf ~/_bkup/mosct.com/jmla.tar.gz ~/public_html/jmla
  • /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/mosct.com/jmla.tar.gz ~/public_html/jmla
(1) Ref: SiteGnd support ticketID: 138159
(2) This command will compress with full directory structure, e.g /home/mysite/public_html/jmla, and have email notification
  • cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/forum.6m.org/forum_6m.tar.gz forum/* >/dev/null 2>&1
(1) Ref: SiteGnd support ticketID: 138924. <-- tested Good as of k06_1217(Sun)
(2) compress without full directory structure and no email notification

Backup a MySQL database

  1. Database to be backed up: mosct_Jmla
  2. Save it to the directroy: /home/mosct/_bkup/mosct.com/
  3. with file name: mosct_Jmla.sql
  4. Cron Job command:
/usr/bin/mysqldump -u mosct_Jmla -pPASSWORD mosct_Jmla > ~/_bkup/mosct.com/mosct_Jmla.sql
  • Add this Cron Job command if compressed file is wanted:
cd ~/_bkup/mosct.com; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf mosct_Jmla.sql.tar.gz mosct_Jmla.sql
  • Remove the intermediate database file "mosct_Jmla.sql":
rm -f /home/mosct/_bkup/mosct.com/mosct_Jmla.sql


Single Cron Job Command

Mosct.com

  • For mosct.com and its dbase mosct_Jmla.sql
/usr/bin/mysqldump -u mosct_Jmla -pPASSWORD mosct_Jmla > ~/_bkup/mosct.com/mosct_Jmla.sql; cd ~/_bkup/mosct.com; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf mosct_Jmla.sql.tar.gz mosct_Jmla.sql; rm -f ~/_bkup/mosct.com/mosct_Jmla.sql; cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/mosct.com/jmla.tar.gz jmla/*
  • When break it down:
  1. Dump the dbase: /usr/bin/mysqldump -u mosct_Jmla -pPASSWORD mosct_Jmla > ~/_bkup/mosct.com/mosct_Jmla.sql
  2. Compress it: cd ~/_bkup/mosct.com; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf mosct_Jmla.sql.tar.gz mosct_Jmla.sql
  3. Remove un-compressed: rm -f ~/_bkup/mosct.com/mosct_Jmla.sql
  4. Lastly compress program directory: cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/mosct.com/jmla.tar.gz jmla/*


  • For kb.mosct.com and its dbase mosct_kb.sql:
/usr/bin/mysqldump -u mosct_kb -pPASSWORD mosct_kb > ~/_bkup/kb.mosct.com/mosct_kb.sql; cd ~/_bkup/kb.mosct.com; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf mosct_kb.sql.tar.gz mosct_kb.sql; rm -f ~/_bkup/kb.mosct.com/mosct_kb.sql; cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/kb.mosct.com/kb.tar.gz kb/* >/dev/null 2>&1
  • When break it down:
  1. Dump the dbase: /usr/bin/mysqldump -u mosct_kb -pPASSWORD mosct_kb > ~/_bkup/kb.mosct.com/mosct_kb.sql
  2. Compress it: cd ~/_bkup/kb.mosct.com; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf mosct_kb.sql.tar.gz mosct_kb.sql
  3. Remove un-compressed: rm -f ~/_bkup/kb.mosct.com/mosct_kb.sql
  4. Compress program directory: cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/kb.mosct.com/kb.tar.gz kb/*
  5. Disable Email Notification: >/dev/null 2>&1


"6MillionDollarPage.org"

  • For en_hnLifekb.org and its dbase tefagrou_6mHnL.sql:
/usr/bin/mysqldump -u tefagrou_6mHnL -pPASSWORD tefagrou_6mHnL > ~/_bkup/en_hnlifekb.org/tefagrou_6mHnL.sql; cd ~/_bkup/en_hnlifekb.org; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf tefagrou_6mHnL.sql.tar.gz tefagrou_6mHnL.sql >/dev/null 2>&1; rm -f ~/_bkup/en_hnlifekb.org/tefagrou_6mHnL.sql; cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/en_hnlifekb.org/en_hnlife.tar.gz en/* >/dev/null 2>&1;


  • For forum.6m.org and its dbase tefagrou_6mF.sql:
/usr/bin/mysqldump -u tefagrou_6mF -pPASSWORD tefagrou_6mF > ~/_bkup/forum.6m.org/tefagrou_6mF.sql; cd ~/_bkup/forum.6m.org; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf tefagrou_6mF.sql.tar.gz tefagrou_6mF.sql >/dev/null 2>&1; rm -f ~/_bkup/forum.6m.org/tefagrou_6mF.sql; cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/forum.6m.org/forum_6m.tar.gz forum/* >/dev/null 2>&1;
  • When break it down:
  1. Dump the dbase: /usr/bin/mysqldump -u tefagrou_6mF -pPASSWORD tefagrou_6mF > ~/_bkup/forum.6m.org/tefagrou_6mF.sql;
  2. Compress it: cd ~/_bkup/forum.6m.org; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf tefagrou_6mF.sql.tar.gz tefagrou_6mF.sql >/dev/null 2>&1;
  3. Remove un-compressed: rm -f ~/_bkup/forum.6m.org/tefagrou_6mF.sql;
  4. Compress program directory: cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/forum.6m.org/forum_6m.tar.gz forum/* >/dev/null 2>&1;
Note: ">/dev/null 2>&1" is for Disabling Email Notification


  • For hnLife.6m.org and its dbase tefagrou_6mHnL.sql:
/usr/bin/mysqldump -u tefagrou_6mHnL -pPASSWORD tefagrou_6mHnL > ~/_bkup/hnlife.6m.org/tefagrou_6mHnL.sql; cd ~/_bkup/hnlife.6m.org; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf tefagrou_6mHnL.sql.tar.gz tefagrou_6mHnL.sql >/dev/null 2>&1; rm -f ~/_bkup/hnlife.6m.org/tefagrou_6mHnL.sql; cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/hnlife.6m.org/hnlife_6m.tar.gz hnlife/* >/dev/null 2>&1
  • When break it down:
  1. Dump the dbase: /usr/bin/mysqldump -u tefagrou_6mHnL -pPASSWORD tefagrou_6mHnL > ~/_bkup/hnlife.6m.org/tefagrou_6mHnL.sql;
  2. Compress it: cd ~/_bkup/hnlife.6m.org; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf tefagrou_6mHnL.sql.tar.gz tefagrou_6mHnL.sql >/dev/null 2>&1;
  3. Remove un-compressed: rm -f ~/_bkup/hnlife.6m.org/tefagrou_6mHnL.sql;
  4. Compress program directory: cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/hnlife.6m.org/hnlife_6m.tar.gz hnlife/* >/dev/null 2>&1;


dsite.mosct.com

  • For dsite.mosct.com and its dbase mosct_dsite.sql
cd ~/_bkup/dsite.mosct.com; /usr/bin/mysqldump -u mosct_dsite -pPASSWORD mosct_dsite > mosct_dsite.sql; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf mosct_dsite.sql.tar.gz mosct_dsite.sql; rm -f mosct_dsite.sql; cd ~/public_html; /usr/local/cpanel/bin/cpuwatch 8.0 /bin/tar -zcf ~/_bkup/dsite.mosct.com/dsite.tar.gz dsite/* >/dev/null 2>&1


MyanmarArtClub.com

  • backup the databases: martclub_mac & martclub_g2; & backup the directories: ~/public_html/mac & ~/public_html/gallery;
cd ~/_bkup; /usr/bin/mysqldump -u martclub_mac -pPASSWORD martclub_mac > martclub_mac.sql; /usr/bin/mysqldump -u martclub_g2 -pPASSWORD martclub_g2 > martclub_g2.sql; /usr/bin/zip -1 martclub_mac.sql.zip martclub_mac.sql >/dev/null 2>&1; /usr/bin/zip -1 martclub_g2.sql.zip martclub_g2.sql >/dev/null 2>&1; rm -f martclub_mac.sql martclub_g2.sql; cd ~/public_html; /bin/tar -zcf ~/_bkup/martclub_mac.tar.gz mac; /bin/tar -zcf ~/_bkup/martclub_gallery.tar.gz gallery; >/dev/null 2>&1;

set the permissions for a folder/file recursively

  • Ref: SiteGnd Support TicketID: 138460
/bin/chmod -R 755 /home/tefagrou/target_folder


Recovering the database Backup

by CronJob Commands

  • Assume:
  • dbase backup: /home/mysite/_bkup/mosct.com/mosct_Jmla.sql.tar.gz
  • First untar the file by:
cd ~/_bkup/mosct.com; /usr/local/cpanel/bin/cpuwatch 7.0 tar xipzf mosct_Jmla.sql.tar.gz mosct_Jmla.sql;
  • then recover the database by:
/usr/bin/mysql -u mosct_Jmla --password=PASSWORD mosct_Jmla < ~/_bkup/mosct.com/mosct_Jmla.sql;

by phpMyAdmin (import)

  • untar "mosct_Jmla.sql.tar.gz" to "mosct_Jmla.sql" in local computer
  • run phpMyAdmin (from cpanel)
-> select the database mosct_Jmla
-> select all the tables and drop them all
-> select "import" -> "utf-8" character set (if your database is in utf-8)
-> "Browse" -> select the downloaded "mosct_Jmla.sql" from your local computer,
-> click "go"
-> That's it!