Replicating the package setup from one CentOS system to another can be crucial for maintaining consistency across environments, especially when dealing with multiple servers or migrating to new hardware. Here’s a step-by-step guide to achieve this without using cloud snapshot functions.

Step 1: Export the List of Installed Packages

On the source CentOS system, you can create a list of all installed packages using the following command:

rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" > installed_packages.txt

This command lists all installed RPM packages with their names, versions, release numbers, and architecture, and saves the list to installed_packages.txt.

Step 2: Transfer the Package List

Transfer the installed_packages.txt file to the new CentOS system. You can use scp, rsync, or any other file transfer method. For example:

scp installed_packages.txt user@new-centos-system:/path/to/destination

Step 3: Resolve Dependencies

Before installing the packages on the new system, ensure that the repositories are configured similarly to the source system. This may involve copying repository configuration files from /etc/yum.repos.d/ or ensuring that the same third-party repositories are enabled.

Step 4: Install the Packages on the New System

On the new CentOS system, read the package list and install the packages:

xargs -a installed_packages.txt sudo yum install -y

The xargs command reads the package names from installed_packages.txt and passes them to yum install.

Considerations

  • Repository Configuration: Ensure that the same repositories are available and enabled on the new system.
  • System-Specific Packages: Some packages might be specific to the hardware or configuration of the original system. Review the list and adjust as necessary.
  • Updates: After installing the packages, it’s a good idea to update the system to ensure all packages are up to date:
    sudo yum update -y
    

Alternative Method Using yum History

If you want to replicate the exact state of the system, including transaction history, you can use yum history.

1. Export Yum History from the Source System

sudo yum history list all > yum_history.txt

2. Transfer the Yum History File to the New System

scp yum_history.txt user@new-centos-system:/path/to/destination

3. Replay the Yum History on the New System

This step is more complex and may require scripting to parse and replay the history. Directly replaying history is not a built-in feature of yum, so manual intervention or custom scripts might be necessary.

Conclusion

By following these steps, you can effectively replicate the package setup from one CentOS system to another without relying on cloud snapshot functionality. This method ensures consistency and saves time when setting up new systems or migrating existing setups.