Jump to content

Join our Slack

Talk to other users and have a great time
Slack Server

Welcome to our Community

Click here to get your Exiled Bot license
Donation Store
Sign in to follow this  
alkpone

CRON Table script

Recommended Posts

Hey, if anybody knows how to write a CRON table script able to first save some folder and some mysql databases in an archive daily, feel free to help here or in pm.

I though that it would be a good idea to make some automatic backups of site and database.

And indeed I didn't made any linux script for years and help would be greatly appreciated.

Share this post


Link to post
Share on other sites

Something like this - didn't test it though

#!/bin/bash

# Set Paths
orig="/path/to/data/folder"
bu="/path/to/backup/folder/"

# Set MySQL info
user="mysqluser"
password="mysqlpassword"
host="localhost"
dbname="dbname"
options="-Q -c -C --add-drop-table --add-locks --quick --lock-tables"


# Set current timestamp
now="$(date '+%Y-%m-%d_%H:%M')"

# Go to original folder
cd "${orig}"

# Make MySQL dump
mysqldump -u${user} -p${password} -h{$host} "${options}" "${dbname}" > "backup.sql"

# Go to backup location
cd "${bu}"

# Make backup
tar cvfz "backup_${now}.tgz" "${orig}"

# Delete mysql backup file
rm "${orig}/backup.sql"

cron entry:

0 3 * * * bash "/path/to/backup_script.sh" >> /dev/null 2>&1

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...