title: Linux shell script for database backup
body: <p>I tried many scripts for database backup but I couldn't make it. I want to backup my database every hour.<br>
  I added files to "/etc/cron.hourly/" folder, changed its chmod to 755, but it didn't run.
  At least I write my pseudo code.</p>
  
  <p>I would be happy if you can write a script for this operation and tell me what should I do more ?
  After adding this script file to <code>/etc/cron.hourly/</code> folder.</p>
  
  <ul>
  <li>Get current date and create a variable, <code>date=date(d_m_y_H_M_S)</code></li>
  <li>Create a variable for the file name, <code>filename="$date".gz</code></li>
  <li>Get the dump of my database like this <code>mysqldump --user=my_user --password=my_pass --default-character-set=utf8 my_database | gzip &gt; "/var/www/vhosts/system/example.com/httpdocs/backups/$("filename")</code></li>
  <li>Delete all files in the folder <code>/var/www/vhosts/system/example.com/httpdocs/backups/</code> that are older than 8 days</li>
  <li>To the file <code>"/var/www/vhosts/system/example.com/httpdocs/backup_log.txt"</code>, this text will be written: <code>Backup is created at $("date")</code></li>
  <li>Change the file owners (chown) from root to "my_user". Because I want to open the backup and log files from the "my_user" FTP account.</li>
  <li>I don't want an email after each cron. <code>&gt;/dev/null 2&gt;&amp;1</code> will be added.</li>
  </ul>