How to change syncing policy for Repositories on Satellite 6 from "Immediate" to "On-Demand".
Environment
- Red Hat Satellite 6
- 6.3 - 6.9 (pulp-2)
- 6.11+ (pulp-3)
- no procedure exists for 6.10
Issue
- Need to change syncing policy from "Immediate" to "On-Demand" in order to free disk space.
Resolution
Please note the below procedure(s) can work on either Satellite 6.9 or older (with pulp-2), or on 6.11 or newer (with pulp-3 AND "Reclaim Space" feature implemented). There is no procedure for Satellite 6.10.
WARNING: This will remove all RPMs that were uploaded via hammer or the UI for repositories that are not synchronized from a remote source. These packages will need to be re-uploaded after running the below steps.
WARNING: This action is irreversible and data-loss may occur as you are forcibly removing all previously downloaded and uploaded RPMs. Creating a VM snapshot or backing up your Satellite before performing this operation is highly recommended
1) Backup your Satellite 6 Server using foreman-maintain. (including pulp content)
2) During the below steps, prevent any repository synchronization and ideally also client yum/dnf activity.
3) Change policy for each repository to "On-Demand" using the rake command below:
Note: This will also change the kickstart repositories to on demand which might be something you do not want - manual change for those repos e.g. in WebUI must follow
# foreman-rake katello:change_download_policy DOWNLOAD_POLICY=on_demand
Now, follow steps depending on Satellite / pulp version:
Subsequent step for Sat 6.11+ (pulp-3)
For any repository that changed Download Policy to On Demand, Reclaim its space. Either via WebUI -> the repository page -> Select Action -> Reclaim Space, or e.g. via hammer repository reclaim-space
command.
Subsequent steps for Sat 6.9 or older (pulp-2)
4) Delete all the files on the file system which are stored at:
# rm -rf /var/lib/pulp/content/units/{rpm,srpm,drpm,distribution}
5) Update the database with the following script:
#!/usr/bin/env python
try:
from pymongo import MongoClient
except ImportError:
print 'Error: PyMongo module is not installed'
exit()
client = MongoClient()
db = client.pulp_database
collections_list = [db.units_rpm, db.units_srpm, db.units_drpm, db.units_distribution]
def mongoupdate(collection):
print "Updating collection " + collection.name
results = collection.update_many(
{"downloaded": True},
{"$set": {"downloaded": False}}
)
print 'Done, updated ' + str(results.modified_count) + " records \n"
for i in collections_list:
mongoupdate(i)
count = 0
for i in collections_list:
print '\nChecking if there are any downloaded packages left at ' + i.name + '\n'
cur = i.find({"downloaded": True})
for k in cur:
count += 1
print ' Amount of downloaded packages ' + str(count) + '\n'
count = 0
6) Reload pulp:
# for i in pulp_resource_manager pulp_workers pulp_celerybeat pulp_streamer; do service $i restart; done
7) Resync all the repos with hammer using the --skip-metadata-check true
flag:
USER=username
PASSWORD=password
for id in $(hammer -u $USER -p $PASSWORD repository list | grep yum | awk '{ print $1 }'); do
echo "repository synchronize --id $id --skip-metadata-check=yes --async"
done | hammer -u $USER -p $PASSWORD shell
For more KB articles/solutions related to Red Hat Satellite 6.x Repository Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Repository Issues.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments