cron ジョブを使用して 6 時間ごとにデータベースを削除または削除する方法を知る必要があり、demo .sql を使用してデータベースを作成します。私のcpanelでは、次のようにcronを作成します:
0 0 1 * * /home/escyv/restore_data.sh
そしてcronはコマンドを実行しますが、cronジョブがコマンドを実行するときにドロップまたは切り捨てを行いません。
ここにスクリプト:
restore_data.sh
#! /bin/sh
clear;
#fill in your database information here
user="escyv_cyv";
password="ky21m1";
server="localhost";
database_name="escyv_cyv";
#path to the backup database file
restore_file="0db0/escyv_db.sql";
#here the script deletes all your tables in the database
mysql --user=$user --password=$password -h $server -BNe "SHOW TABLES" $database_name | tr '\n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " $1 ";SET
FOREIGN_KEY_CHECKS = 1;"}' | mysql --user=$user --password=$password -h $server $database_name;
echo "Base de datos limpiandose!";
echo "Restaurando Base de Datos..";
#here the script restores the database
mysql --user=$user --password=$password host=$server $database_name < $restore_file;
echo "Base de datos restaurada!";
サイトにエラーが表示されるかどうかを確認するために、復元ファイルescyv_db.sqlの名前をescyv_db1.sqlに変更してテストしますが、データベース内のすべての情報を表示します...したがって、コマンドは何も作成されていないと思います..
下手な英語でごめんなさい...母国語ではありません
よろしくお願いします!
アンドレス
-----編集----- このスクリプトは機能しています! @itsols に感謝
これは新しい restore_data.sh です。
#! /bin/sh
clear;
#here the script deletes all your tables in the database
mysql -u escyv -pky21m1 -e 'drop database escyv_cyv;'
echo "Base de datos limpiandose!";
mysql -u escyv -pky21m1 -e 'create database escyv_cyv;'
#here the script restores the database
mysql -u escyv_cyv -pky21m1 escyv_cyv < 0db0/escyv_db.sql
echo "Restaurando Base de Datos..";
echo "Base de datos restaurada!";