Recently a client requested that I come up with a CD-based backup solution for their Linux server. After installing the CD-R and getting the system ready to use it, it was time to write some scripts to automate the process of backing up.
Backup downloads directory - saved as "backup_downloads" in /root/bin.
#!/bin/bash
tar -cvf /tmp/backup.tar /var/downloads ; gzip /tmp/backup.tar
mkisofs -r -o /tmp/backup_image /tmp/backup.tar.gz
cdrecord -v speed=4 dev=0,0,0 -data /tmp/backup_image
rm -rf /tmp/backup.tar.gz /tmp/backup_image
Backup documents & system files - saved as "backup_documents" in /root/bin.
#!/bin/bash
tar -cvf /tmp/backup_docs.tar /var/documents /var/complaints_log /var/qckbks50 /etc /var/yp ; gzip /tmp/backup_docs.tar
mkisofs -r -o /tmp/backup_image /tmp/backup_docs.tar.gz
cdrecord -v speed=4 dev=0,0,0 -data /tmp/backup_image
rm -rf /tmp/backup_docs.tar.gz /tmp/backup_image
I combined documents & system files because /etc & /var/yp together compress down to 3 MB, so it's silly to put those onto one CD-R by themselves.
#!/bin/bash
Required for a shell script. Tells the shell script which shell we're using; in this case, bash, the default Linux shell.
tar -cvf /tmp/backup.tar /var/downloads ; gzip /tmp/backup.tar
The first part, before the semicolon, creates a tarfile called "something.tar" from the list of directories following the tarfile's name. Immediately after creating the tarfile, the system uses gzip to compress the tarfile, ultimately resulting in a file called "something.tar.gz".
mkisofs -r -o /tmp/backup_image /tmp/backup.tar.gz
Before writing to a CD-R, an ISO file must be created. This line creates that ISO file, called "backup_image", from the tar.gz file.
cdrecord -v speed=4 dev=0,0,0 -data /tmp/backup_image
Finally the CD-R is written using cdrecord. The ISO image is transferred to the CD-R. Notice that I used a speed of 4. The CD burner supports speeds up to 40x; however, the CD-Rs that you buy in stores rarely match those speeds. In this case, a slower speed guarantees more compatibility. Since this is a backup script that will run automatically at 4 a.m., the extra 10 minutes or so it will take are inconsequential.
rm -rf /tmp/backup.tar.gz /tmp/backup_image
A bit of cleanup at the end as the .tar.gz file and the ISO image are both deleted.
That's it. The client can now backup their files. Order and safety are restored.
|