Skip to content

Instantly share code, notes, and snippets.

@intel352
Last active December 22, 2015 14:44
Show Gist options
  • Save intel352/5774772 to your computer and use it in GitHub Desktop.
Save intel352/5774772 to your computer and use it in GitHub Desktop.
Handy one-liners
# List name vhosts on current server (excludes aliases)
sudo apache2ctl -S 2>&1 | grep -v 'Syntax OK' | grep 'namevhost' | tr -s ' ' | cut -d' ' -f5
# List all vhosts and aliases on current server
THECONFS="`apache2ctl -S 2>&1 | grep -oE '\/[^\:]+' | grep -vE '^\s*#'`"; for ACONF in ${THECONFS}; do cat ${ACONF} | tr '\t' ' ' | grep -E '^ *(ServerName|ServerAlias)' | sed -r 's/^( |ServerName|ServerAlias)+//g' | tr ' ' '\n'; done | sort -fu
# Replace DATABASENAMES and HOSTNAME in the commands below before running.
# TODO: update grants to only apply to the DATABASENAMES listed.
# Transfer DBs
mysqldump --routines --databases DATABASENAMES | bzip2 | ssh HOSTNAME 'bunzip2 | mysql'
# Transfer users/privs
mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
'SHOW GRANTS FOR \'', user, '\'@\'', host, '\';'
) AS query FROM mysql.user WHERE user NOT LIKE 'root' AND user NOT LIKE 'debian-sys-maint'" | \
mysql $@ | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' | \
ssh HOSTNAME mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment