Jump to content
Sign in to follow this  
Foster

Create a cron to save your Db on the server

Recommended Posts

Hello,

 

This tutorial allow you to create a cron to save your db in daily.

if you want to change the delay, you can use this site to help you : https://crontab-generator.org/

 

Inside your server create a files : saveCronTabDb.sh with execute right (chmod 755)

 

#!/bin/bash


DB_USER='MyUserName'
DB_PASS='MyPassword'
DB_HOST='localhost'
DB_NAME='MyTable'

mysql -u${DB_USER} -p${DB_PASS} -h${DB_HOST} $DB_NAME < "/var/www/xxx/xxx/web8/web/myDbdirectory/myDbfilesToSave.sql"

 

Now you can create your crontab with this command: In this case all the 21hr everyday

 

* */21 * * * /var/www/xxx/xxx/web1/private/saveCronTabDb.sh > /var/www/xxx/xxx/web1/private/cron.log

 

To test your cron :

sh saveCronTabDb.sh

 

To see your cron

 

sudo crontab -l

Ah do not forget to protect your directory with an htaccess

 

# Disable directory browsing 
Options -Indexes

<Files .htaccess>
Order allow,deny
Deny from all
</Files>

 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use