ArielGlenn has uploaded a new change for review. https://gerrit.wikimedia.org/r/117888
Change subject: puppetize the weekly centralauth mysql dump ...................................................................... puppetize the weekly centralauth mysql dump Change-Id: Ib64278d57fb18adb3b84a079f017c8b00fa7e301 --- A files/misc/scripts/dumpcentralauth.sh A manifests/role/snapshot.pp 2 files changed, 149 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/88/117888/1 diff --git a/files/misc/scripts/dumpcentralauth.sh b/files/misc/scripts/dumpcentralauth.sh new file mode 100755 index 0000000..9638880 --- /dev/null +++ b/files/misc/scripts/dumpcentralauth.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +usage() { + echo "Usage: $0 --site <datacenter> [--config <pathtofile>] [--dryrun]" + echo + echo " --site pmtpa, eqiad, etc" + echo " --config path to configuration file for dump generation" + echo " (default value: /backups/dumps/production/confs/wikidump.conf" + echo " --dryrun don't run dump, show what would have been done" + exit 1 +} + +configfile="/backups/dumps/production/confs/wikidump.conf" +dryrun="false" +site="" + +while [ $# -gt 0 ]; do + if [ $1 == "--config" ]; then + configfile="$2" + shift; shift + elif [ $1 == "--dryrun" ]; then + dryrun="true" + shift + elif [ $1 == "--site" ]; then + site="$2" + shift; shift + else + echo "$0: Unknown option $1" + usage + fi +done + +if [ -z "$site" ]; then + echo "site parameter is mandatory." + usage +fi + +private=`egrep "^private=" "$configfile" | mawk -Fprivate= '{ print $2 }'` +mysqldump=`egrep "^mysqldump=" "$configfile" | mawk -Fmysqldump= '{ print $2 }'` +apachedir=`egrep "^dir=" "$configfile" | mawk -Fdir= '{ print $2 }'` +gzip=`egrep "^gzip=" "$configfile" | mawk -Fgzip= '{ print $2 }'` +if [ -z "$private" -o -z "$mysqldump" -o -z "$gzip" -o -z "$apachedir" ]; then + echo "failed to find value of one of the following from config file $configfile:" + echo "private, mysqldump, gzip, dir" + echo "exiting..." + exit 1 +fi + +wmfconfigdir="${apachedir}/wmf-config" +multiversionscript="${apachedir}/multiversion/MWScript.php" +dbphpfile="${wmfconfigdir}/db-${site}.php" +if [ ! -f "$dbphpfile" ]; then + echo "failed to find $dbphpfile, exiting..." + exit 1 +fi + +dbcluster=`grep centralauth "$dbphpfile" | mawk -F"'" ' { print $4 }'` +if [ ! "$dbcluster" ]; then + echo "no db cluster available for this site, exiting..." + exit 1 +fi + +wiki=`grep $dbcluster "$dbphpfile" | grep wiki | head -1 | mawk -F"'" ' { print $2 }'` +host=`echo "echo wfGetLB()->getServerName(wfGetLB()->getReaderIndex(false,'$wiki')); " | php "$multiversionscript" eval.php $wiki` +if [ -z "$dbcluster" -o -z "$wiki" -o -z "$host" ]; then + echo "can't locate db server for centralauth, exiting." + exit 1 +fi + +wikiadmin=`echo 'echo $wgDBadminuser;' | php "$multiversionscript" eval.php $wiki` +wikipass=`echo 'echo $wgDBadminpassword;' | php "$multiversionscript" eval.php $wiki` +if [ -z "$wikiadmin" -o -z "$wikipass" ]; then + echo "can't get db user name and password, exiting." + exit 1 +fi + +tables="global_group_permissions global_group_restrictions global_user_groups globalblocks globalnames globaluser localnames localuser migrateuser_medium spoofuser wikiset" +today=`date +%Y%m%d` +dir="$private/centralauth/$today" +mkdir -p "$dir" +for t in $tables; do + outputfile="$dir/centralauth-$today-$t.gz" + if [ "$dryrun" == "true" ]; then + echo "would run:" + echo -n "$mysqldump" -u "$wikiadmin" -p"$wikipass" -h "$host" --opt --quick --skip-add-locks --skip-lock-tables centralauth "$t" + echo "| $gzip > $outputfile" + else + echo "dumping $t into $outputfile" + "$mysqldump" -u "$wikiadmin" -p"$wikipass" -h "$host" --opt --quick --skip-add-locks --skip-lock-tables centralauth "$t" | "$gzip" > "$outputfile" + fi +done diff --git a/manifests/role/snapshot.pp b/manifests/role/snapshot.pp new file mode 100644 index 0000000..607d120 --- /dev/null +++ b/manifests/role/snapshot.pp @@ -0,0 +1,58 @@ +class role::snapshot::common { + include accounts::datasets +} + +class role::snapshot::cron::centralauthdump($enable=true) { + include role::snapshot::common + + file { '/usr/local/bin/dumpcentralauth.sh': + mode => '0755', + owner => 'root', + group => 'root', + source => 'puppet:///files/misc/scripts/dumpcentralauth.sh', + } + + # used by script to find the name of the correspondaing db.php file + if ($::site == 'eqiad') { + $dbsite = $::site + } + else { + $dbsite = 'secondary' + } + + if ($enable == true) { + $ensure = 'present' + } + else { + $ensure = 'absent' + } + + system::role { 'role::snapshot::cron::centralauthdump': + ensure => $ensure, + description => 'mysql dumper of centralauth', + } + + cron { 'centralauth-dump': + ensure => $ensure, + command => "/usr/local/bin/dumpcentralauth.sh --site ${dbsite} --config /backups/dumps/production/confs/wikidump.conf", + environment => 'MAILTO=ops-du...@wikimedia.org', + user => datasets, + minute => '15', + hour => '8', + weekday => '6', + require => [File['/usr/local/bin/dumpcentralauth.sh'], + User['datasets']], + } +} + +class role::snapshot::cron::primary { + class { 'role::snapshot::cron::centralauthdump': + enable => true, + } +} + +class role::snapshot::cron::secondary { + class { 'role::snapshot::cron::centralauthdump': + enable => false, + } +} -- To view, visit https://gerrit.wikimedia.org/r/117888 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib64278d57fb18adb3b84a079f017c8b00fa7e301 Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: ArielGlenn <ar...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits