Backup CentOS Linux RPM database

Q. How do I backup CentOS Linux server RPM database?

Advertisement

A. /var/lib/rpm directory stores all files used by rpm command. All files inside this directory are binary files. It has the information about all installed package. You can easily backup all files using following method.

Backup Linux RPM Database stored at /var/lib/rpm directory

a) Login as the root user.

b) First remove any stale lock file, enter:
/bin/rm -f /var/lib/rpm/__db*

c) The next step is to back up the /var/lib/rpm directory, using tar command:
# tar czvf $(hostname).rpmdatabase.tar.gz /var/lib/rpm
If your hostname is linux-server, it will save backup to a file called linux-server.rpmdatabase.tar.gz

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

1 comment… add one
  • Leon Jul 29, 2020 @ 1:50

    The second step is improper. In /var/lib/rpm directory, there are __db.001, __db.002, __db.003 which are binary database. Following the instruction, user would delete these database and lose the data. For safety consideration, I suggest run below script
    tar czvf $(hostname).rpmdatabase.tar.gz /var/lib/rpm –exclude=”*.lock”

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.