• Dear Pleskians! The Plesk Forum will be undergoing scheduled maintenance on Monday, 7th of July, at 9:00 AM UTC. The expected maintenance window is 2 hours.
    Thank you in advance for your patience and understanding on the matter.

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