On FreeBSD, you can use the pkg
command to backup and restore a list of installed packages.
- Backup installed packages: To create a backup of the currently installed packages, you can use the command
pkg backup -d backup_directory
. This command will create a file called “pkg-backup.txz” in the specified directory (in this case “backup_directory”) that contains a list of all installed packages. - Restore packages from a backup: To restore packages from a backup file, you can use the command
pkg add backup_directory/pkg-backup.txz
. This command will install all the packages that were included in the backup file. - Backup a list of packages to a file: To backup a list of packages to a file, you can use the command
pkg query -a %n > package_list.txt
. This command will list all the packages that are currently installed and write them to the package_list.txt file. - Restore packages from a list file: To restore packages from the list file, you can use the command
xargs pkg install < package_list.txt
. This command will read the package_list.txt file and install all the packages listed in it.
Please note that these commands are for basic usage, and you can customize them according to your needs. Also, before making any changes, it’s recommended to have a backup plan in case something goes wrong, and also to test the changes before applying them to your production environment.
Also, it’s important to note that the package backup feature is not intended to be used as a migration tool between systems. It’s intended to provide a means of taking a snapshot of the system’s package state, so that the packages can be later reinstalled on the same system.