# Replication Installed Ports



## Lames (Mar 22, 2012)

Hi friends,

I have installed several FreeBSD's and all servers work fine. Same ports are always installed on each server. Could you tell me why it's possible to export all installed ports in order to reinstall on other server AND export config file too?

I'm searching in the freebsd FreeBSD forum and in /usr/ports/ports-mgmt without results.

I'm making a little script for listing all ports:
`pkg_info -a -o | grep -A1 'Origin:' | grep -v 'Origin:' | grep -v '-'`

Then *I* install ports on the new server. But for configuration files, it's more complicated. Should *I* copy the /usr/local/etc directory?

What is your experience in production?

Thanks a lot

have a good day

Lames


----------



## pestaa (Mar 25, 2012)

I believe you're approaching the problem from a wrong direction.

You have multiple servers and want to configure them identically. The situation yells for a configuration management system like Puppet or cfengine. (Although I'm currently looking at cdist as it seems a lot more shell-friendly.)


----------



## Lames (Mar 26, 2012)

*Solved*

Thanks a lot for your reply. Effectively, *I*'m searching in the wrong way. I knew these solutions but I did not know what I could adapt in port configuration.

*T*hank you for your good advice.

*H*ave e nice day,
Lames


----------



## frijsdijk (Mar 26, 2012)

The part about the config files I'm not sure, but if you create packages from your ports while you install them, just copy the packages to the other server and *pkg_add* them.

Some packages will install config files like /usr/local/etc/package.conf.sample.. so I don't think that if you create /usr/local/etc/package.conf later on, it will be included if you make packages of that installed port (pkg_create). If the servers are exaclty the same, you might even consider using rsync on /usr/local/etc/.


----------



## Chris_H (Mar 26, 2012)

Greetings,
 This is an area that I've been pondering in the back of my mind for some time. But as I read this thread, just now. It occurred to me that the simplest answer might just be, with the aid of cat(1), sed(1), awk(1), echo(1), and ls(1). One might create a port (ports(7))
called "myports". That merely installed all of the ports that were installed on the machine you wish to model your others after. It seems a simple process of using cat(1), sed(1), awk(1), echo(1), and ls(1) to gather the contents of [cmd=""]/var/db/ports[/cmd]
and create a 
	
	



```
RUN_DEPENDS
```
 line for the [cmd=""]Makefile[/cmd]
There's also the need to prepend the category, define the "ports base", and such. But it's all quite trivial using those commands to cobble up a script to build a [cmd=""]Makefile[/cmd] for a port (ports(7)) called "myports", that would build up a base you consider "standard fare", on any FreeBSD installation. To insure that the ports(7) are configured (config(8)) with you specific needs, is simply a matter of spamming your /etc/make.conf(5) with your needed options, copying it to your targets /etc/make.conf(5), and commit a rehash(1), all prior to running make(1) on the new "myport" Makefile, on the target machine. Please keep in mind this is all off the top of my head, and I'm writing this from a "smart phone", and don't have access to any of my FreeBSD boxes right now. Or I would have provided an actual script to accompany this, and this would have been written nicer. :\


----------



## wblock@ (Mar 26, 2012)

Some people have made such meta-ports, but there's currently an easier way.  On the original system, run
`% portmaster --list-origins > ~/installed-port-list`

Copy the entire /var/db/ports/ directory to the target system.  On the target system:
`# pkg_add -r rsync && rehash`
`# rsync -avz user@originalmachine:/var/db/ports/ /var/db/ports/`

Also copy and set up any special configurations, like /etc/make.conf.

Copy installed-port-list to the target system and update the ports tree on it.  Then
`# pkg_add -r portmaster && rehash`
`# portmaster `cat ~/installed-port-list``

A more brute force version of this is to dump(8)/restore(8) the entire original system to the target system.  Then everything is identical, and it just needs minor adjustments on the target.


----------

