Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After hours and hours work, I created a solution like the below. I copy paste for other people that can benefit.</p> <p>First create a script file and give this file executable permission.</p> <pre><code># cd /etc/cron.daily/ # touch /etc/cron.daily/dbbackup-daily.sh # chmod 755 /etc/cron.daily/dbbackup-daily.sh # vi /etc/cron.daily/dbbackup-daily.sh </code></pre> <p>Then copy following lines into file with Shift+Ins</p> <pre><code>#!/bin/sh now="$(date +'%d_%m_%Y_%H_%M_%S')" filename="db_backup_$now".gz backupfolder="/var/www/vhosts/example.com/httpdocs/backups" fullpathbackupfile="$backupfolder/$filename" logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" &gt;&gt; "$logfile" mysqldump --user=mydbuser --password=mypass --default-character-set=utf8 mydatabase | gzip &gt; "$fullpathbackupfile" echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" &gt;&gt; "$logfile" chown myuser "$fullpathbackupfile" chown myuser "$logfile" echo "file permission changed" &gt;&gt; "$logfile" find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} \; echo "old files deleted" &gt;&gt; "$logfile" echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" &gt;&gt; "$logfile" echo "*****************" &gt;&gt; "$logfile" exit 0 </code></pre> <p>Edit:<br> If you use InnoDB and backup takes too much time, you can add "<a href="http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html#option_mysqldump_single-transaction" rel="noreferrer">single-transaction</a>" argument to prevent locking. So mysqldump line will be like this:</p> <pre><code>mysqldump --user=mydbuser --password=mypass --default-character-set=utf8 --single-transaction mydatabase | gzip &gt; "$fullpathbackupfile" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload