Show Table of Contents
3.3. Automated Backups
Backup tasks can be automated so that they occur in non-peak times, such as the late evening or early morning. This also ensures they are performed regularly, and are not forgotten. The most effective way to automate backups is using
cron.
Procedure 3.3. Automating Backups
Create a new file called
backup-db.sh containing the following script. This script will stop the satellite, perform a database backup, and restart the satellite:
#!/bin/bash
{
/usr/sbin/rhn-satellite stop
su - oracle -c'
d=db-backup-$(date "+%F");
mkdir -p /tmp/$d;
db-control backup /tmp/$d
';
/usr/sbin/rhn-satellite start
} &> /dev/null
- Create a new file called
move-files.shcontaining the following script. This script will usersyncto move the backup files to a directory to be stored:#!/bin/bash rsync -avz /tmp/db-backup-$(date "+%F") [destination] &> /dev/null
Replace [destination] with the path to the backup directory.Alternatively, the following script usesscpto achieve the same goal:#!/bin/bash scp -r /tmp/db-backup-$(date "+%F") [destination] &> /dev/null
- Switch to the root user, and open the
crontabin a text editor:crontab -e
Note
Thecrontabwill open in vi by default. To change this behavior, change theEDITORvariable to the name of the text editor you prefer. - In the
crontab, use the first five fields (minute, hour, day, month, and weekday) to schedule the backup scripts to run:0 3 * * * backup-db.sh 0 6 * * * move-files.sh
Thiscrontabentry will run the backup at 03:00, and transfer the backup files at 06:00. Other options can be included as needed. You can also include a clean up script to remove older backup directories and prevent the backup storage from filling up. - To save the
crontab, simply exit from the text editor. The newcronrules will be put in to place immediately.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.