This is a basic script that can be set to run automatically every day, every week or every hour if you like and backup key files and directories.
Applicable to Centos Versions:
- Centos 5.x
Requirements
Explanation of requirements.
- Root or sudo with the appropriate privileges.
Doing the Work
Basic description of what will be done and what is expected.
- Explanation and download link for the script:
- Automating the script to run once daily:
- Running the script:
1 |
<a title="serverbackup.sh" class="fade" href="/scripts/serverbackup.sh">This Script</a> will backup the following directories as tar files with the date and location in the title of the resulting tar files:<br /><br />/etc (location of most of the systems configuration files)<br />/home (location of users home directories/files)<br />/var/log (location of most of the systems logs files)<br />/var/www (location of webserver files and content)<br />/var/lib/mysql (location of raw MySQL databases, all databases are first dumped to a .sql file before the directory is tarred)<br /><br /><strong>The tar files will be stored in:</strong><br />/root/serverbackup/$DATE/ These files can then be moved or another separate storage media to complete the backup.<br /><br /><strong>The tar files will be named like this example:</strong><br />01-Oct-2009-Thu-04:46:42-AM-PDT-host.example.org-etc.tar.gz<br /> |
1 |
Copy <a title="serverbackup.sh" class="fade" href="/scripts/serverbackup.sh">The Script</a> above into the /root directory.<br />chmod +x serverbackup.sh<br />cd /etc/cron.daily; vi 00serverbackup (<strong>hit 'i' to insert text</strong>)<br /><strong>Add this line:</strong><br />bash /root/serverbackup.sh > /dev/null 2>&1<br />Hit 'esc' :wq to exit vi<br />chmod +x 00serverbackup<br /> |
1 |
Copy <a title="serverbackup.sh" class="fade" href="/scripts/serverbackup.sh">The Script</a> to /root<br />chmod +x serverbackup.sh<br />./serverbackup.sh<br /><br />The script will output to the screen so you'll be able to see what's being done. Once it's finished check the /root/serverbackup directory for the tar files.<br /><strong>IMPORTANT:</strong> You'll also need a MySQL DBA with full DBA privileges. The default DBA in the script is: backupdba password: dbapass. Change these to suit your own needs. <br /> |
Troubleshooting
How to test
Explanation troubleshooting basics and expectations.
- Make sure you’ve properly chmoded the script:
1 |
ls -als serverbackup.sh (make sure the "x" permission is set for whatever level user you are, root should be able to execute any executable)<br /> |
Common problems and fixes
Describe common problems here, include links to known common problems if on another site
More Information
Any additional information or notes.
Disclaimer
We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #centos on irc.freenode.net
Added Reading
Last Modified: 22 Apr, 2020 at 16:37:29