Jump to content

edtowens

Members
  • Posts

    4
  • Joined

  • Last visited

Reputation

10 Good

About edtowens

  1. Here it is reggiep, sorry it took me a little while to throw it up for ya. It doesn't have the fixes that powdarmonkey had advised yet. I will try and make those revisions and post them back on this forum. #!/bin/bash #========================================================================================================================== # Script Name: MoodleRestore *Local* # By: Edward Owens # Date: May 2011 # Purpose: Restore Moodle Root, Moodledata, and Database from the argument of 1 or 2. # MoodleRestore 1 will restore moodle1.zip, MoodleRestore 2 will restore moodle2.zip # This works in tandem with the Backup script I have created, 'MoodleBackup'. #========================================================================================================================== # define variables zip1="/home/edward/Backups/moodle1.zip" # absolute path to backupfile 1 zip2="/home/edward/Backups/moodle2.zip" # absolute path to backupfile 2 lbesql="/home/edward/Backups/moodle_db.sql" # absolute path to sql file after extraction logname="/home/edward/Backups/restore_log" # absolute path to restore log dbPassword="password" # mysql password dbUser="user" # mysql user DBNAME="databasename" # mysql db name DBEXISTS=$(mysql --batch --skip-column-names -e "SHOW DATABASES LIKE '"$DBNAME"';" | grep "$DBNAME" > /dev/null; echo "$?") # does database exist? if [ $DBEXISTS -eq 0 ];then echo "Dropping database because it exists" mysqladmin -u[$dbUser] -p[$dbPassword] drop [$DBNAME] fi if [ "$1" -eq "1" ]; # Want to restore backup file 1 then if test -e $zip1; # Does backup file 1 exist? then unzip -o $zip1 -d "/" >> $logname mysql -u $dbUser -p -D$DBNAME --password=$dbPassword < $lbesql rm $lbesql else echo $zip1" does not exist. Make sure you run MoodleBackup first!" exit fi else if [ "$1" -eq "2" ]; # Want to restore backup file 2 then if test -e $zip2; # Does backup file 2 exist? then unzip -o $zip2 -d "/" >> $logname mysql -u $dbUser -p -D$DBNAME --password=$dbPassword < $lbesql rm $lbesql else echo $zip2" does not exist. Make sure you run MoodleBackup first!" exit fi else echo "No file selected" fi fi
  2. Hi powdarrmonkey I will definitely do this. Dreamhost Nice advice and I thank you for it! Since I'm a noob, I'm not sure what you mean by this. I log in FTP and download the backups every other day. I will look into better file testing methods. Honestly, never even thought about, but now I will! Thanks, Edward Owens
  3. Thank you for your response reggiep. I will get that restore script up in a couple of days. The reason I annotate my scripts is because I'm still learning and it makes it easier for me to go over and edit. Plus, when I share it it will help someone else to modify it. I too struggle with linux and scripts, but I'm finding it much fun! Thanks, Edward Owens
  4. Hi all, I would really like someone to look this over and tell me if they see some problems with security or potential problems with corruption. I have ran this script locally using ubuntu 10.10 using LAMP. Everything appears to work correctly. I have a vps and have successfully ran this script there also. I don't know what linux version my host is using but it seems to work. I place this script outside the webroot in a folder called Backups. This will create two backups only. If there are two backups already it will overwrite the oldest one. I didn't want to have a drive filled up with backups. You could alter it to create as many as you like though. I have created a restore script also that basically reverses the backup script.I left path information because it is just my local setup. Let me know what you think. If you want, I will also post my restore script. #!/bin/bash #========================================================================================================================== # Script Name: LocalMoodleBackup # By: Edward Owens # Date: April 2011 # Purpose: Backup Moodle, Moodledata, and Database and zip them in a single zip file. Keep only two backups on hand. # If there is already two backups on hand, then overwrite the oldest one. #========================================================================================================================== #------Variables----------------------------------------------------------------------------------------------------------- suffix=$(date +%B-%Y) # date stamp logname="/home/edward/Backups/"$suffix"_backup.log" # absolute path to logfile file_name1="/home/edward/Backups/moodle1.zip" # absolute path to backup 1 file_name2="/home/edward/Backups/moodle2.zip" # absolute path to backup 2 zip1="/home/edward/webdev/domainname.com/" # absolute path to moodle root zip2="/home/edward/webdev/moodledata/" # absolute path to moodle data sql_name="/home/edward/Backups/moodle_db.sql" # absolute path to sql file dbName="my dbname" # db Name dbUser="my dbuser" # db User dbPassword="mypassword" # db Password dbHost="my dbhost" # db Host #---------------------------------------------------------------------------------------------------------------------------- echo "Started--> "$(date +%H":"%M":"%S) > $logname echo "Dumping database" mysqldump --opt --user=$dbUser --password=$dbPassword --host=$dbHost $dbName > $sql_name if test -e $file_name1; then if test -e $file_name2; then echo "copying moodle2.zip to moodle1.zip" cp $file_name2 $file_name1 >> $logname echo "removing moodle2.zip" rm $file_name2 >> $logname echo "creating moodle2.zip" zip -r $file_name2 $zip1 $zip2 $dbname >> $logname else echo "creating moodle2.zip" zip -r $file_name2 $zip1 $zip2 $dbname >> $logname fi else echo "creating moodle1.zip" zip -r $file_name1 $zip1 $zip2 $dbname >> $logname fi # remove sql file echo "removing "$sql_name rm $sql_name echo "Finished--> "$(date +%H":"%M":"%S) >> $logname echo "Finished--> "$(date +%H":"%M":"%S)
×
×
  • Create New...