Created
February 18, 2015 10:33
-
-
Save iammart/f627d0fb995ed985627a to your computer and use it in GitHub Desktop.
Loop through a list of directories, grab relevant database and archive the files.
This file contains 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
#!/usr/bin/bash | |
filename="$1" | |
USER=root | |
PASS= | |
while read -r line | |
do | |
name=$line | |
hasfound=false | |
echo "Looking for Database $line" | |
sleep 5 | |
for dir in /var/lib/mysql/${name}* | |
do | |
# Unset flag | |
hasfound= | |
database=$(basename "$dir") | |
echo "Database $database found!" | |
echo "Dumping database" | |
mysqldump --opt --user=${USER} $database > "/home/$name/public_html/$database.sql" | |
echo "Changing permissions" | |
chown ${name}:${name} "/home/$name/public_html/$database.sql" | |
echo "Database dumped to /home/$name/public_html/$database.sql" | |
sleep 2 | |
done | |
if ! [ "$hasfound" ]; then | |
echo "No database found for ${name}" | |
sleep 2 | |
fi | |
echo "Archiving $name" | |
sleep 5 | |
tar zcvf "/home/archive/$name.tgz" -C "/home/$name/public_html/" . | |
echo "Archiving complete for $name.tgz" | |
read -p -u 3 "press [enter] to continue..." | |
done < "$filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment