• Halloween is coming! To celebrate the occasion, we dusted off a couple of old skins, and even created a brand new one (Pixel).
    To get into the festive spirit, install the Skins extension.
  • The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

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