skip to Main Content

In my provider, those functions are disabled:

exec,passthru,shell_exec,system

thus in my backupping script, I cant execute mysqldump and tar command. Then what can I do?

2

Answers


  1. For the database part : As an alternative, you may use SELECT * INTO OUTFILE

    For details, refer to Mariadb offical documentation and Mysql official documentation

    So a typical syntax can be (if you want to specify the format)

    SELECT customer_id, firstname, surname from customer
      INTO OUTFILE '/exportdata/customers.txt'
      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY 'n';
    

    So the sample code (say using mysqli) is (amend to suit your needs):

    <?php
    // Connect to the database
    $conn = mysqli_connect('host', 'username', 'password', 'database');
    
    
    // Export the database
    $sql = "SELECT * from table_name INTO OUTFILE '/path/to/backup.sql'";
    
    if (mysqli_query($conn, $sql)) {
      echo "Database backup successfully created!";
    } else {
      echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
    
    // Close the connection
    mysqli_close($conn);
    
    ?>
    

    Note: if you want to "restore" your data, use LOAD DATA INFILE ... . See official documentation

    Login or Signup to reply.
  2. cronjob

    This assumes the backup is run by the root user, but the process is very similar if it is at the account level.

    /etc/cron.d/backup

    If you have root access (which is probably unlikely)

    MAILTO=root
    33 3 * * * root ./backup.sh
    

    crontab -e

    If you don’t have root access

    33 3 * * * ./backup.sh
    

    /root/backup.sh

    Rotating 7-day backup

    #!/bin/bash
    cd $HOME
    DOW=`date '+%a'`
    mysqldump db -udbuser | gzip > db-"$DOW".sql.gz
    

    /root/.my.cnf

    There are more secure solutions, but if the user has access to your root account and directory, it’s too late anyway

    [client]
    user=dbuser
    password=dbpassword
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search