Need to create a RH Satellite database dump by Red Hat support request (example script).
Hello all,
The below script I made with input of Red Hat Support to create the database dumps and put the output in a tar file
cd /var/tmp
mkdir foreman_db
cd foreman_db
su - postgres -c "psql foreman -c '\dt *.*'" | grep foreman | awk '{ print $3 }' > _tables.txt
for i in $(cat _tables.txt ); do echo $i; su - postgres -c "psql foreman -c 'select * from $i;'" > ${i}.txt; done
cd ..
mkdir candlepin_db
cd candlepin_db
su - postgres -c "psql candlepin -c '\dt *.*'" | grep candlepin | awk '{ print $3 }' > _tables.txt
for i in $(cat _tables.txt );
do
echo $i
su - postgres -c "psql candlepin -c 'select * from $i;'" > ${i}.txt
done
cd ..
mkdir pulp_db
cd pulp_db
echo "DBQuery.shellBatchSize = 10000000" > .mongorc.js
mongo pulp_database --eval "db.getCollectionNames()" | grep , | tr ',' '\n' | cut -d\" -f2 > _tables.txt
for i in $(cat _tables.txt )
do
echo $i
mongo pulp_database --eval "load('.mongorc.js')
db.${i}.find().shellPrint()" > ${i}.txt
done
for i in $(cat _tables.txt )
do
echo $i
mongo pulp_database --eval "load('.mongorc.js');
db.${i}.find().pretty().shellPrint()" > ${i}.pretty.txt
done
cd ..
tar cvzpf satellite-db_dump-$(date +"%F-%H%M").tgz foreman_db candlepin_db pulp_db
rm -rf foreman_db
rm -rf candlepin_db
rm -rf pulp_db
cd ~