Talk:Automatic Backup

From DreamHost

Jump to: navigation, search

Thanks Matttail, for the great article. So clear that even I could follow it and get it right!




Hello Mattail. Thank you for the article. I would like to point one thing out though. #!/bin/bash cd /home/username/backups/ mkdir mysql suffix=$(date +%y%m%d) mysqldump --opt -uUser -ppass -h mysqlA.domain.com db_nameA > backups/mysql/db_nameA.$suffix.sql mysqldump --opt -uUser -ppass -h mysqlB.domain.com db_nameB > backups/mysql/db_nameB.$suffix.sql tar -cf archives/mysql_backup.$suffix.tar backups/mysql/* rm -r backups/mysql/

That is the original code for mysql.sh. It was giving me lots of problems, and this is my first time even seeing bash stuff, but I found that modifying the code to look like this fixed my problems.

#!/bin/bash cd /home/username/backups/ mkdir mysql suffix=$(date +%y%m%d) mysqldump --opt -uUser -ppass -h mysqlA.domain.com db_nameA > mysql/db_nameA.$suffix.sql mysqldump --opt -uUser -ppass -h mysqlB.domain.com db_nameB > mysql/db_nameB.$suffix.sql tar -cf archives/mysql_backup.$suffix.tar mysql/* rm -r mysql/

It seems to me that although you switched to the directory backups on line two, later in the script you assumed the user was at /home/username.

I hope this helps someone else.

Contents

Further Compression with gzip Command

I would suggest changing the example to compress the files as they are added to the archive. The code would be,

#!/bin/bash

rm /home/username/backups/all*.gz

suffix=$(date +%y%m%d)

cd /home/username/.snapshot/

tar -zvcf /home/username/backups/all.$suffix.tar.gz -X /home/username/backups/exList nightly.0/

The changes by line number are:

2) Delete any previous archive files. This saves room on your disk space allotment and should not cause any problems because the point of these archive procedures is to download the backup to a separate disk (i.e. away from your server).

5) The -zvcf causes the files to be gzip'd as they are added to the archive. This may reduce the file size by 50% or better. The v tag can be removed, it simply causes the names of the files archived to be written on the screen. The -X command causes the exList file to be read for filenames that will not be added to the archive (this can also save a lot of file space if one uses it to ignore software installation files, such as th includes directory of a Joomla installation).

If this seems confusing, removing the -X and the exList reference after it will cause the entire directory of the user to be archived.

Finally, maybe a link to the following helpful forum post would be useful: Hot-To: Using-Tar

--Pikepace 07:23, 9 April 2007 (PDT)

No datestamps

No datestamps. I haven't re-validated that the scripts here work. -Kelly 09:07, 6 April 2007 (PDT)

I can't see why not. If people don't want datestamps, they can just remove that part. But it makes sense to explain how to do it for those who do want to know what state of the database the backup represents. Also, keeping only one backup is bad because if your data got corrupted before the last backup you're screwed. Also you didn't change the explanation so the article is inconsistent now. => reverted it--Jane Doe 04:33, 7 April 2007 (PDT)

File Access Control

Instead of chmod 755 on mysql.sh, I think chmod 750 would be better. Is there a reason for giving the world read/execute on your backup script? (Especially because you have to include your passwords in it!)

Also, adding a umask 027 to the beginning of the script prevents anything being created world accessible. DreamHost default umask is 002 (rw-rw-r--), which is very reasonable for a Web service (but not locked-down by default).

However, I'm new to DreamHost. Can someone of authority describe whether/if DreamHost prevents shared system users from accessing other user files (beyond UNIX file permissions)?

Thanks for this handy guide, by the way!

nice -19 !?!

Are you sure you mean nice -19?? Remember, many command switches in Linux do NOT require a dash (-) before them. In this case, the nice manpage indicates that -20 is highest priority (i.e., not very nice at all). I'd recommend just using nice with no specified priority (default of 10, which is reasonably nice).

Indeed, and more specifically the correct command should be nice -n 19 for a NICE process. I'm not even sure if nice -19 does anything, as you typically need to pass on the -n option, which effectively works to tell nice to adjust the level of niceness. Also, as a note, we were told in irc not long ago by a staff member that nice doesn't have much of an affect anymore, as processes are already pre-niced by the server. Just food for thought.-- Mousee 07:15, 18 April 2007 (PDT)
Personal tools