Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Location
    USA
    Posts
    9

    Unanswered: Automatic Table Backup

    Hi Need help in writing a script for automatic table backup everyday at a particular time

    I want the contents of the table to be copeid to another table on the same server at a particular time everyday. If a backup copy already exists the script shud check to see if it exists , delete it and then load a fresh copy of the data again.

    I know mysqldump does something similar but I jus a want a basic intro and I can go from there

    Thanks
    -Kri

  2. #2
    Join Date
    Jul 2004
    Location
    Dundee, Scotland
    Posts
    107
    -> so if you are using Linux you'll be using cron to run a script at a certain time each day. you are unlikley to call a PHP script. you are likely to run a script which logs into the MySQL database and then runs a few queries.

    re "If a backup copy already exists the script shud check to see if it exists , delete it and then load a fresh copy of the data again."
    -> For example, use:
    DROP TABLE IF EXISTS `database_name`.`backup_table_name` ;

    CREATE TABLE `database_name`.`backup_table_name` (
    `received` date NOT NULL default '0000-00-00',
    `replied` date NOT NULL default '0000-00-00'
    ) TYPE = MYISAM ;

    INSERT INTO `database_name`.`backup_table_name`
    SELECT *
    FROM `database_name`.`live_table_name` ;


    note: depending on your needs you might prefer to clear the data in the backup table using the following "truncate" statement instead of dropping and re-creating the backup table:
    TRUNCATE TABLE `temp2`;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •