Last active
December 22, 2015 14:44
-
-
Save intel352/5774772 to your computer and use it in GitHub Desktop.
Handy one-liners
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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