• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.

Cronjob question

J

Jimmy1980

Guest
Hello.

On our webserver we want to create a weekly mysqldump of some databases and want to do this by a cronjob.

Problem is, when the cronjob is executed, the "old" file will be overwritten and this mustn't happen. Are there some variables I can use to give the file a date or something?

I hope you understand what I want... :) If not - ask.


Thank you for your help,
Jimmy
 
In your script you can append the date to the end of the filename.

This line will get the a date variable like "2006-07-25"

date=`/bin/date +%F`


Then add it to your file name in the script with:
filename_$date
 
Hi.

Thank you for your reply.

I don't use a script to do my backup. I created a new cronjob in the crontab of the server managemet. I only have a commandline there where I typed the following:

cd /home/httpd/vhosts/<domain>/;
mysqldump -u <user> --password=<pw> <db> > filename.sql

This command runs fine and I get my file every day but the old file will be overwritten if I don't move it into another location.

There for I wanted to add a date, so that my filename is always different.


How do I create a script like yours, which filetype do I have to use and whats about the content? :)


Thank you.
 
Instead of having this entry in the crontab, create a file with a text editor ( I use the command #vi filename ) and enter the following:


#/bin/bash
date=`/bin/date +%F`

cd /home/httpd/vhosts/<domain>/;
mysqldump -u <user> --password=<pw> <db> > filename_$date.sql


Then, in the crontab, enter the script name instead of the command you now have. The crontab will run this script which in turn will create your mysqldump with the date appended to the filename.

I normally put my scripts like this in the "bin" folder and give root ownership. Also do a chmod to 750 to allow it to run.
 
Back
Top