ICTNUT Posted February 25, 2008 Posted February 25, 2008 Hi all, not sure if this should be here or in the scripts section but here goes. I have to backup a linux server each night and would like to acheive the following: A full copy backup of the /usr/var/www/*.* folder A full copy backup of each mysql database on the server A full copy backup of the /usr/var/moodledata folder The contents of the above should be copied into /var/backups/[date]/ with the file structure of each remaining intact and an additional folder being created for the MySQL_DataBackup. Once the above has completed I need it to be FTP'd of to another server which will then be burned to DVD hopefully. Any pointers on where to start or if anyone has anything like this would be great.
DarkLight Posted February 25, 2008 Posted February 25, 2008 You could look into using rsync for synchronizing your "live" data with your "backup" data on another server. You can use rsync with a cronjob to automatically backup your files each night and get them transferred over to your backup server. Regarding your MySQL database you could either dump the database and backup the copy, sync/replicate the database or a number of other options. Sorry I don't really have any information links to hand right at this moment in time, but if any come up I'll be sure to post them. Best Regards,
kmount Posted February 25, 2008 Posted February 25, 2008 Something like this should do it. mkdir /var/backups/`date +%Y-%m-%d%n` cd /var/backups/`date +%Y-%m-%d%n` cp -R /usr/var/www . cp -R /usr/var/moodledata . mkdir ./MySQL_DataBackup mysqldump -u root --password=doodah --all-databases > ./sql-`date +%Y-%m-%d%n`.sql gzip sql-`date +%Y-%m-%d%n`.sql mount -t smbfs -o username="servername\username",password=doodahpassword //servername/share /var/backups/link2backupserver cp -R /var/backups/`date +%Y-%m-%d%n` /var/backups/link2backupserver
ICTNUT Posted February 25, 2008 Author Posted February 25, 2008 @kmount: If i am reading your script right: 1 - Make the backup directory 2 - Change into the directory 3 - Copy /usr/var/www/*.* while maintaining structure 4 - Copy /usr/var/moodledata/*.* while maintaining structure 5 - Make the MySQL_Backup folder 6 - Dump the sql databases into the above folder (question to follow) 7 - Mount to a file share with relevant permissions on a windows box 8 - Copy the full backup folder over. Am i far off?? Question regarding step 6, is this a single file dump or are they seperate for each database (i have 7 in total) How would you schedule this to run each night??
kmount Posted February 25, 2008 Posted February 25, 2008 Yup, you're correct. If you want to do dump the backup of each database individually you can, for example. mysqldump -u root --password=doodah mydb1 > ./mydb1-`date +%Y-%m-%d%n`.sql mysqldump -u root --password=doodah mydb2 > ./mydb2-`date +%Y-%m-%d%n`.sql mysqldump -u root --password=doodah mydb3 > ./mydb3-`date +%Y-%m-%d%n`.sql The gzip line just compresses them for the sake of sanity/space.
ICTNUT Posted February 25, 2008 Author Posted February 25, 2008 Ahh cool that makes sense. What about running as a scheduled script each night, what would be the best way of doing this?? You will have to forgive me on this as I am no *nix guru but need to have some sort of backup plan in place and seeing as this is such a key server, well I guess you understand.
kmount Posted February 25, 2008 Posted February 25, 2008 On linux, sheduled tasks go by the name of cronjob/tabs. So, as root you'd need to do the following: Log in as root (since you're needing to grab files from everywhere, otherwise not a good idea). Put the content of the script into /root/doBackup.sh chmod it 700 so its executable by root but not readable by anyone else Type crontab -e which will drop you into a text editor where you put the entry below. 30 23 * * * sh /root/doBackup.sh Will run it at 23:30hrs each evening. Have a look here for more info. Hope this helps. 1
ICTNUT Posted February 25, 2008 Author Posted February 25, 2008 Thanks very much kmount much apreciated
contink Posted February 25, 2008 Posted February 25, 2008 This might be a bit more useful or easier to setup on the mysql side of things. http://www.edugeek.net/forums/showthread.php?t=13986&highlight=backup
ICTNUT Posted February 25, 2008 Author Posted February 25, 2008 Just a quick one, what do they following lines do: /var/backups/link2backupserver just trying to work out what link2backupserver is?
Geoff Posted February 26, 2008 Posted February 26, 2008 Your backup device needs to be accessable from the script. In this case, it needs to be mounted in the directory you've mentioned. It depends on what you backup device actually is though on how to do this.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now