From owner-freebsd-questions@FreeBSD.ORG Thu Feb 11 16:15:14 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DDB831065670 for ; Thu, 11 Feb 2010 16:15:14 +0000 (UTC) (envelope-from amvandemore@gmail.com) Received: from mail-qy0-f189.google.com (mail-qy0-f189.google.com [209.85.221.189]) by mx1.freebsd.org (Postfix) with ESMTP id 78F3E8FC08 for ; Thu, 11 Feb 2010 16:15:14 +0000 (UTC) Received: by qyk27 with SMTP id 27so867414qyk.3 for ; Thu, 11 Feb 2010 08:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=Jired7xQY1IArdw0AFhHT1B8wik6VMvNxedCwzsfCO8=; b=hNoYREl2Bd1teogZUiuUV6wmwjzVYWErjCL92Tg5ak3BnpYv2Qoqvu1l6iItv3cOar E1ylddGR+cUHrBSovckBOtKlIYzty3OikqcVQQtbi5rS0/BMZ/xLijHw9v/RqIxd5GMJ N4RY2KM+Hv2kL1XsWm7t6NXYgLLKYDo1fynIA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=B3tUgCOuq4qrwmcbM1lA+3XSApwJYXRdmHTJwif4rJoDXXNtCEas+oGViAj2Ik2z/5 nhWZDH8C4hVtMNzt2zka9pJ5gCK9JOM7yzU2UmzuWyqTOiOJM9E8BKxBWHuzLtF4ANec VE0Ksv+8+Sofdz34YCAvTM7z1ocEMKWQqbakc= MIME-Version: 1.0 Received: by 10.142.59.19 with SMTP id h19mr30515wfa.243.1265904912993; Thu, 11 Feb 2010 08:15:12 -0800 (PST) Date: Thu, 11 Feb 2010 10:15:12 -0600 Message-ID: <6201873e1002110815l312da12fr5388956f32465516@mail.gmail.com> From: Adam Vande More To: FreeBSD Questions Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: python script to backup installed packages X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Feb 2010 16:15:14 -0000 Sometimes you have need to backup installed packages. I realize most port management tools do this automatically, but if you're on a system with a lot of packages installed and one port management tool fails and you use another to fix it, /usr/ports/packages can become jumbled. Anyways, I've written a simple python script which will create a fresh snapshot of all installed packages. These are convenient for backups or installing on a new system. For anyone interested: from subprocess import Popen, PIPE import os s = Popen('pkg_info -a | grep : | grep Information',shell=True,stdout=PIPE).communicate()[0] pkg_location = '/data/packages' packages = [] for line in s.split('\n'): info = line.replace('Information for ', '').replace(':','') packages.append(info) os.chdir(pkg_location) for package in packages: s = Popen('pkg_create -b ' + package,shell=True,stdout=PIPE).communicate()[0] -- Adam Vande More