-
-
Save crcastle/6eb329de90a27b1e2ed7 to your computer and use it in GitHub Desktop.
backup Homebrew packages. See http://www.topbug.net/blog/2013/12/07/back-up-homebrew-packages/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| brew_command=/usr/local/bin/brew | |
| brew_cask_command="$brew_command cask" | |
| echo '#!/bin/bash' | |
| echo '' | |
| echo 'trap ctrl_c INT' | |
| echo 'function ctrl_c() {' | |
| echo 'echo "** Trapped CTRL-C"' | |
| echo 'exit 1' | |
| echo '}' | |
| echo '' | |
| echo 'brew_command=/usr/local/bin/brew' | |
| echo 'brew_cask_command="$brew_command cask"' | |
| echo 'failed_items=""' | |
| echo 'function install_package() {' | |
| echo 'echo EXECUTING: brew install $1 $2' | |
| echo '$brew_command install $1 $2' | |
| echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed to install.' | |
| echo '}' | |
| echo 'function install_cask_package() {' | |
| echo 'echo EXECUTING: brew cask install $1' | |
| echo '$brew_cask_command install $1' | |
| echo '[ $? -ne 0 ] && $failed_items="$failed_items $1" # package failed to install.' | |
| echo '}' | |
| $brew_command tap | while read tap; do echo "$brew_command tap $tap"; done | |
| $brew_command list | while read item; | |
| do | |
| echo "install_package $item '$($brew_command info $item | /usr/bin/grep 'Built from source with:' | /usr/bin/sed 's/^[ \t]*Built from source with:/ /g; s/\,/ /g')'" | |
| done | |
| $brew_cask_command list | while read item; | |
| do | |
| echo "install_cask_package $item" | |
| done | |
| echo '[ ! -z $failed_items ] && echo The following items were failed to install: && echo $failed_items' |
Author
This is great, thanks for sharing! Do you know if Homebrew has some sort of native support for backing up the taps and formulas (or are they planning to add that feature)?
Any guidance on how to modify the script to pull out package options now that the "Built from source with:" has been changed to "Built from source on (date) at (time) with:"?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use Homebrew, use this script to backup your installed packages -- including cask packages! This makes setup on a new machine super fast.
backup-homebrew.shto your computer and make it executable. Don't copyrestore-homebrew.sh. That's just an example of the restore file that you'll create.crontab -eto schedule the script to run regularly. I run it every 6 hours. See my crontab entry above for an example. It overwritesrestore-homebrew.shevery time it runs with a list of all your currently installed homebrew packages.restore-homebrew.shexecutable and execute it. All of your homebrew and homebrew cask packages will be automagically installed!Bonus: If you use Dropbox, put the script and its output file in a Dropbox folder (see my crontab entry for an example of where I store the files) so you have it backed up should your hard drive die or computer go missing.