# Backup for Ports or Packages



## arnab (May 25, 2016)

Hi all, recently I have installed gimp, Virtualbox, Eclipse through pkg-install(8) command and a few more from ports collection. Now my questions is that can I backup these specific packages or ports in a dvd or usb backup tool from which I can install them later without internet connection? And one more thing to ask that can I backup kde desktop environment also as it takes a lot of time to download.


----------



## SirDice (May 25, 2016)

Have a look in /var/cache/pkg/.


----------



## arnab (May 25, 2016)

There (var/cache/pkg) are a lots of compresses packages how can I identify which one to select? And how to install them later?


----------



## ANOKNUSA (May 25, 2016)

You'd probably want to back up everything, since both the package and its dependencies get downloaded.

Packages can be installed by just specifying the path to the package archive with `pkg install`. You could also have a look at pkg-repo(8). Would make it much easier to reinstall should the need arise.[/cmd]


----------



## arnab (May 25, 2016)

I found that 
  To create a package repository catalogue you must specify the top-level
  directory where all the packages are stored as repo-path.  pkg repo will
  search the filesystem beneath repo-path to find all the packages it con-
  tains.  Directories starting with ".
  "" or named Latest are not traversed.
But how to select a specific package or port and take a copy of them for further use?


----------



## arnab (May 25, 2016)

I did this 
`pkg create -a
pkg repo .` and found a huge number of compressed folders of the whole system...... Don't know what to do next


----------



## pkubaj (May 25, 2016)

arnab said:


> I did this
> `pkg create -a
> pkg repo .` and found a huge number of compressed folders of the whole system...... Don't know what to do next


You can set up a new repo for pkg(8):

```
poudriere: {
  url: "file:///usr/local/poudriere/data/packages/local-default",
  mirror_type: "NONE",
  signature_type: "none",
  enabled: yes
}
```

Put your directory in there and put the file in /usr/local/etc/pkg/repos. If you want to be able to use it on other computers, set up e.g. FTP server and for the repo config in /usr/local/etc/pkg/repos use:

```
poudriere: {
  url: "ftp://192.168.11.3/amd64-default-serwer",
  signature_type: "none",
  enabled: yes
}
```


----------



## arnab (May 25, 2016)

actually FreeBSD is my primary os. On it I have installed Virtualbox and on Virtualbox again I have installed Freebsd. Now you see it is a very time consuming process to download every package and install them so I asked that if there is any way to take a copy of those basic packages to install them on the virtual machine. But i didn't understand that after creating the tar package Do i have to save them on a pendrive or dvd?


----------



## pkubaj (May 25, 2016)

arnab said:


> actually FreeBSD is my primary os. On it I have installed Virtualbox and on Virtualbox again I have installed Freebsd. Now you see it is a very time consuming process to download every package and install them so I asked that if there is any way to take a copy of those basic packages to install them on the virtual machine. But i didn't understand that after creating the tar package Do i have to save them on a pendrive or dvd?


You could just set up FTP/HTTP server and make the VM download the packages from the server.


----------



## arnab (May 25, 2016)

Can I setup a FTP/HTTP server on my machine, i.e. on the host machine?


----------



## pkubaj (May 25, 2016)

arnab said:


> can i setup a FTP/HTTP server on my machine i.e on the host machine?


Please, RTFM:
https://www.freebsd.org/doc/en/books/handbook/network-apache.html
https://www.freebsd.org/doc/en/books/handbook/network-ftp.html


----------



## tobik@ (May 25, 2016)

arnab said:


> can i setup a FTP/HTTP server on my machine i.e on the host machine?


It sounds like you don't need a permanent server for this. For example if you install devel/py-twisted you can run an ad-hoc server on the host whenever you need to install packages in your VMs with:

```
twistd -n web --path=/path/to/your/repository -p 8000
```
(This runs the server on port 8000, adjust your repository configuration accodingly.) If your finished you can kill it with Ctrl-C.

P.S.: Python's has a builtin HTTP server too which you can use with `python2 -m SimpleHTTPServer`. I usually use Twisted's web server for stuff like this because it supports resuming downloads. But that is probably not important here.


----------



## arnab (May 25, 2016)

thanks all for four suggestion but I'm still not sure that if I am able to create a copy of my packages by pkg create -a command. Do you know any other process to do so? I have found a link but not sure that it would be able to create package backups of my system or not
poudriere: { url: "file:///usr/local/poudriere/data/packages/local-default", mirror_type: "NONE", signature_type: "none", enabled: yes }


----------



## SirDice (May 25, 2016)

Instead of trying to go backwards (build a repository from an existing system), consider going forward (build new system from repository). You can do this on your host or in a 'special' virtual machine. It's going to be a time consuming job but once it's done you'll have a perfectly tuned offline package repository. Set up a build repository using ports-mgmt/poudriere or ports-mgmt/synth. You mentioned you had to build some ports because of certain options you needed? Both will allow you to set those in advance. Once the tool is finished building everything you need, share it using www/nginx (small, simple web server). Other VMs, and the host itself, can use this repository to install and/or update. You would only need internet access when the build tool does its job. It will download things once. It will build the port using _your_ settings so your packages are all set to go. You can copy the repository to USB, CD or anywhere else you want.

Build once, install many


----------

