Cron command to backup a website

Posted on 2006-04-22
Last Modified: 2011-10-03
Apache, Fedora core 2. In plesk the automated backup command doesnt work, so is there a cron command I can use to backup the database and files daily?

Question by:lexxwern
    LVL 51

    Expert Comment

    for the database you need to use the tools provided by the database, otherwise the backed up files may be inconsistent
    In most ceses you have to shutdown the database, perform the back up, then restart the database.
    I'd write a script for that which also create a targall or rsyncs your other files, then simply call this script from cron.
    LVL 18

    Expert Comment

    by:Sam Panwar

    Its pretty easy to write a script with PHP that will run the mysql dump command, and transfer the sql file produced to another server through FTP. You can set this up as a cron job to run daily, to copy the data to another server through FTP, or just produce the sql file and you can download it manually through FTP. You could also use PHP to automate the process of
    using gzip to zip up the site files, and sending it to another server through FTP.
    LVL 23

    Accepted Solution


    Scheduling With the at Command

    You can use the at command to schedule a command or script to run a single time. The command includes several utilities.

    If you want to schedule a command more than once, look into the crontab command.

    By default, only the root user can use the at command. However, the root user can use two files to allow regular users the command:

    /etc/at.allow: If this file exists, only users listed in it can use the command.

    /etc/at.deny: If this file exists, users listed in it cannot use the command.

    The at command depends on a plain text file. This file lists commands or scripts, one per line. The end of the file must be marked by <EOT> on a line by itself.

    The time for a task can be set using several formats. The simplest is a 24 hour clock in the hh:mm format, followed by the date in the mm: dd:yyyy format.

    You can enter commands by entering the name of a plain text file in which commands or scripts are listed, one per line. Type: at -f file command time date .

    LVL 23

    Expert Comment


    Scheduling With the crontab Command

    You can use the crontab command to run commands at regular times. For example, you could schedule a backup of your files every Friday. Commands can be scheduled to the minute.

    If you want to schedule a command to run only once, look into the at command.

    The crontab command works by reading a crontab file. A crontab file is a plain text file that lists all the jobs you have scheduled.

    Each line of the crontab file consists of the command with all its options and arguments, and the date and time to run it.

    By default, all users can set up their own crontab files. However, the root user can use two files to control access:

    /etc/cron.allow: If this file exists, only users listed in it can use crontab.

    /etc/cron.deny: If this file exists, users listed in it cannot use crontab.

    All crontab files are stored in the /var/spool/cron/crontabs/ directory. However, since regular users do not have read or write permission to this directory, they must use the crontab command to schedule jobs.

    Cron, as supplied in Debian, has two purposes:

    To run system jobs on a daily/weekly/monthly basis

    To allow users to setup their own schedules

    The system schedules are setup when the package is installed, via the creation of some special directories:


    Except for hte first one which is special, these directories allow scheduling of system-wide jobs in a coarse manner. Any script which is executable and placed inside them will run at the frequency which its name suggests.

    For example if you place a script inside /etc/cron.daily it will be executed once per day, every day.

    The time that the scripts run in those system-wide directories is not something that an administration typically changes, but the times can be adjusted by editing the file /etc/crontab. The format of this file will be explained shortly.

    The normal manner which people use cron is via the crontab command. This allows you to view or edit your crontab file, which is a per-user file containing entries describing commands to execute and the time to execute them.

    LVL 12

    Author Comment

    Sorry about that abandoning .. work is tough :(( :((

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now