Is this your first visit? You may want to subscribe to the feed.

Articles tagged with backup

Network Time Machine backups to another Mac

For a while now I’ve been wanting to setup Time Machine on my MacBook Air to backup to the external drive plugged into my Mac Mini, but one thing has been stopping me: transferring 80GB over wifi. I’ve tried it a couple times and even after 24 hours it’s nowhere near done (Time Machine slowness + wifi slowness = double slowness).

I also tried getting an initial backup by plugging the drive directly into my MacBook and then moving it back to the Mini once it’s done. But Time Machine stores network backups differently than it does if the drive is plugged in locally. When backing up over a network, it creates a sparse bundle disk image.

So last night I finally tried again and got it to work. The trick was to start the backup over the network which sets up the sparse bundle, and cancel it shortly after it started. Then when I plug the drive directly into my laptop, Time Machine is smart enough to see the sparse bundle and use that.

Here’s the recipe for getting network backups to an external drive started without doing the initial backup over the network:

  1. Share the drive: With the backup drive still plugged into your host Mac (not the one that needs backed up), share the drive by going to Sharing in System Preferences. Enable file sharing and add the drive to “Shared Folders”.

  2. Start the network backup: First, you need to enable backing up to “unsupported” network volumes (a.k.a. ones you didn’t shell out extra money to apple for). On the machine you want to back up over the network, open up terminal and run:

    defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

    Now, go to Time Machine preferences and you should be able to select your shared drive should appear in the list of disks.

  3. Cancel the backup: After the backup is done preparing and starts copying data, cancel it.

  4. Attach drive directly: Eject your external drive from the host machine and plug it directly into the machine you want to back up. There should be a file on it titled [machine-name]_[MAC-address].sparsebundle. Make sure there is NOT a folder in Backups.backupdb with your machine name. I believe Time Machine will try to use that if it exists instead of using the sparse bundle.

    Now go to Time Machine preferences and switch your backup drive to the local drive. It should run a full backup now using the sparse bundle.

  5. Switch back to network backup: Move your drive back to your host machine and switch Time Machine preferences to use the network disk. Sit back and enjoy network backups.

This worked for me. Let me know in the comments how it works for you.

The network backups have been working great so far. I closed my laptop while a backup was running this morning. When I opened my laptop back up on a new network, it complained that the network connection had been lost to the backup drive, but as soon as I got home this evening, the backup started again immediately.

Code: backup Jan 14, 2009 ● updated Jan 14, 2009 8 comments

Awesomeness: database backups

At Collective Idea, we have a plugin called awesomeness that is…well, awesome. It’s a collection of things that we use in almost every project that aren’t generic enough to go into individual plugins (although some things may have evolved enough to be worthy of plugin status).

A while ago, I blogged a little snippet for backing up your remote database. Well, that snippet as evolved quite a bit, into it’s own set of rake and Capistrano tasks.

First, the rake tasks. You Can easily create a new local backup:

$ rake db:backup:create

This creates a backups directory in your project, with a subdirectory for each backup based on the timestamp. A backup consists of the schema.rb file and then a fixture for each table to hold the data. Why fixtures? Good question. Because we wanted the backups to be database independent.

You can easily restore your local database to the latest backup, or a specific version:

$ rake db:backup:restore VERSION=20080427214315

That’s nice, but what good are local backups? That’s where Capistrano comes in. Just add this to your config/deploy.rb:

load 'awesomeness/backup'

This adds some nifty remote backup support. Now, whenever cap deploy:migrations is run, a backup of your remote database will automagically be created and stored in the shared directory on the server. You can also have them transferred to your local machine by adding a callback in your deploy.rb:

after "backup:create", "backup:download"

Sometimes, you just want to take a snapshot of the server and plop it into your local database.

$ cap backup:mirror

How do I get this backup awesomeness?

Awesomeness now lives on Github (like the rest of the world). Fork it and let us know what you think.

Code: backup Apr 27, 2008 ● updated Oct 14, 2008 2 comments

Automatically backing up your remote database on deploy

Ever had a migration fail when you’re deploying a sparkling new release of your snazzy web app, leaving your database in an inconsistent state? I have. Fortunately, a faulty migration has never completely hosed my production database, but I have had to ssh in, comment some lines out of a migration, and re-run it.

Now, I can rest assured that I’ll never have the experience of hosing my production database without being able to recover it. Here are Capistrano recipes to backup your remote production database whenever you run migrate on your remote database.

require 'yaml'

desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
  filename = "#{application}.dump.#{Time.now.to_i}.sql.bz2"
  file = "/tmp/#{filename}"
  on_rollback { delete file }
  db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'database.yml'))).result)['production']
  run "mysqldump -u #{db['username']} --password=#{db['password']} #{db['database']} | bzip2 -c > #{file}"  do |ch, stream, data|
    puts data
  end
  `mkdir -p #{File.dirname(__FILE__)}/../backups/`
  get file, "backups/#{filename}"
  # capistrano < 1.4
  # `rsync #{user}@#{roles[:db][0].host}:#{filename} #{File.dirname(__FILE__)}/../backups/`
  delete file
end

desc "Backup the database before running migrations"
task :before_migrate do 
  backup
end

The backup recipe is adapted from ones presented by Caboo.se and Bojan Mihelac. I modified it to use my local database.yml. Thanks to Daniel Morrison, who came up with the idea of running the backup task before migrating.

Code: backup Feb 09, 2007 ● updated Feb 15, 2007 3 comments

Subscribe

Browse by Tag