Archive for the 'Backups' Category
Switching MySQL Databases on 1and1
After wanting to test Wordpress 3.0 on a 1and1 hosting account, I ran into the following issue… the particular setup I was dealing with had only one database available, and it wasn’t MySQL 5, but instead MySQL 4… furthermore, it was a version lower than 4.1.2, which more recent versions of Wordpress require as a minimum.
So after doing a bit of research on what others had done, I went about fixing the problem. Interestingly enough, 1and1 could have made some money in this situation if they would allow customers to simply purchase another database to add to their packages, but no, they want an entire upgrade to be purchased.
The first step was to backup the website and database. I ssh’ed into the web host:
Then I backed up the database. The command below will dump all of the databases on the host (in this case, only one MySQL 4.x database) into a dated bzip file, in the home directory.
Now to backup the site itself (not only in case disaster struck, but this would get a local copy of the sql dump I just made as well). On a local OS X workstation (or Ubuntu, if that suits your tastes) I ran something similar to the following:
username@localhostname:~$ rsync -avz –exclude="logs" $username@example.com: ~/website_backups/
From there, I was able to log into the 1and1 control panel and delete the existing database. This allowed me to setup a new one, and in particular, choose MySQL 4 or 5 as the type.
Back to the 1and1 hosting account:
I uncompressed the sql dump:
and was greeted with the raw sql in the file, “2010-01-14-01-59-PM-db-backup.sql”. From here it was only a hop skip and a jump away to restoration. It was necessary to edit the sql file in order to have it restore properly to the newly created database that was just created:
And I changed the $oldDatabaseName to $newDatabaseName.
– Current Database: `$oldDatabaseName`
–
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `$oldDatabaseName`;
USE `$oldDatabaseName`;
ctrl+o, enter, and ctrl+x, to save the file and exit nano. The sql dump was now ready to restore to the new database.
The only other things to do were to update any existing applications that needed the new database name, username, hostname, and password.
As a note, if you are updating a Wordpress install to point to a new database, this info can be changed in the file, wp-config.php.
Posted by Karl Herrick on January 14th, 2010 in Wordpress, Backups, Apple, Linux, Hosting, Web Development, Bash | No Comments »
Time Machine Size Limits
So I have this new My Book World Edition, and I set it up to allow for Time Machine backups. The problem? On OS X, Time Machine wants to eat up almost the entire amount of free space before it goes about deleting old files… (un)conveniently there is no option to restrict the size of the backups.
Never fear… I google’d a bunch and found that if you run the following command on the Mac doing the backups:
It doesn’t appear to do anything (or may possibly do something else that isn’t related to what I was after).
So, I went about it in a different manner. If I clicked on the Time Machine icon (rotating clock) in the menu bar, and clicked “Enter Time Machine”… exited the GUI of Time Machine, and then opened terminal, I could do the following:
- Become root:
sudo -s
- Goto the /Volumes directory, and look for which folder is mounted for Time Machine backups:
cd /Volumes && ls -l
- Enter the folder that is mounted for Time Machine backups:
cd $Mount_Point_For_Backups
- Look for the .sparsebundle file that is being used for backing up the workstation:
ls -l
- Resize the sparsebundle file:
hdiutil resize -size 200g $hostname.sparsebundle
The sparse image is then resized, and Time Machine will report that there is only around 200 gigabytes total available space rather than around a terabyte (which is the original size of the drive). ![]()
Posted by Karl Herrick on January 2nd, 2010 in Backups, Apple, Linux, Bash | 1 Comment »
Client to Server Backups
I have intentions to look into Bacula as a disk-to-disk backup solution, however until then I am using the following script for Kubuntu Dapper -> Debian Etch backups, and a modified one for Windows XP Home -> Debian Etch.
It all uses rsync, and requires password-less key based ssh connections. I am using rsync, OpenSSH, and for Windows XP a little Cygwin magic (including modifying this script to make it Windows friendly).
client-to-server-rsync-backup.sh
#!/bin/bash
#ver 1.0.3
BACKUPSERVERUSER=limitedUserOnServer
BACKUPSERVER=serverHostName
BACKUPCLIENT=`echo $(hostname -s) | tr '[:upper:]' '[:lower:]'`
BACKUPS=(
#localFolder,backupDestinationParentFolder
#/home,/media/md2/backups/clientname
#/var/www,/media/md2/backups/clientname/var
)
if [ "$1" != "--incremental" ] && [ "$1" != "--sync" ] && [ "$1" != "--help" ]; then
echo $0: missing operand
echo Try `$0 --help' for more information.
elif [ "$1" = "--help" ]; then
echo " Usage: $0 [OPTION]... [PASSTHROUGH OPTIONS]";
echo "";
echo " Mandatory arguments:";
echo " [OPTION]";
echo " --incremental add to the existing backups";
echo " --sync sync the live data with the existing backup";
echo "";
echo " Optional arguments:";
echo " [PASSTHROUGH OPTIONS]";
echo " Passthrough options are sent to rsync in this form from this script:";
echo "";
echo " for incremental:";
echo " sudo rsync -avz [PASSTHROUGH OPTIONS] $SOURCE $BKUPSRVUSER@ \";
echo " $BKUPSRV:$DEST";
echo "";
echo " and for sync:";
echo " sudo rsync -avz [PASSTHROUGH OPTIONS] --delete $SOURCE \";
echo " $BKUPSRVUSER@$BKUPSRV:$DEST";
echo "";
echo " * This makes it easy to do something like this:";
echo " * $0 --incremental \"--partial --progress\"";
echo " *";
echo " * Thus sending \"--partial --progress\" to rsync,";
echo " * making this script a little more interactive...";
echo " * read more via `man rsync'.";
else
if [ "$1" = "--incremental" ]; then
incremental_or_sync="";
elif [ "$1" = "--sync" ]; then
incremental_or_sync="--delete";
fi
for BACKUPS in ${BACKUPS[@]}; do
SOURCE=`echo $BACKUPS | cut -d',' -f1`
DESTINATION=`echo $BACKUPS | cut -d',' -f2`
echo
echo "# starting backup"
echo "# from: $BACKUPCLIENT:$SOURCE"
echo "# to: $BKUPSRV:$DEST"
echo
echo sudo rsync -avz $2 $inc_or_sync $SOURCE $BKUPSRVUSER@$BKUPSRV:$DEST
sudo rsync -avz $2 $inc_or_sync $SOURCE $BKUPSRVUSER@$BKUPSRV:$DEST
echo
done
fi
Posted by Karl Herrick on March 15th, 2008 in Backups, Windows, Linux, Bash | No Comments »