EvilZone
Programming and Scripting => Scripting Languages => : ca0s August 29, 2011, 06:11:44 PM
-
#!/bin/sh
FECHA=`date +%d-%m-%Y--%H-%M`
#Cleanup
rm SQL.sql
rm SQL.sql.gpg
#Backup SQL
mysqldump -A -u root -pmypass > SQL.sql
echo pass | gpg --passphrase-fd 0 -c SQL.sql
#Backup Web
tar vczf web.tgz /www/htdocs
echo pass | gpg --passphrase-fd 0 -c web.tgz
#Upload a FTP
ftp -n -v ftp.site.com << EOT
ascii
user ca0s pwd
prompt
cd ka0labs
mkdir $FECHA
cd $FECHA
put SQL.sql.gpg
put web.tgz.gpg
bye
EOT
#Cleanup
rm SQL.sql
rm SQL.sql.gpg
rm web.tgz
rm web.tgz.gpg
Is the first thing I make in bash. I needed it to make SQL/web backups in my VPS.
-
cool, although maybe recommend reading passwds from stdin.. So isn't in your script.
edit: forgot to mention, read has -s option for su type input:
echo -n "enter mysql password: "; read -s sqlpasswd
Also quick tip: rm can take multiple arguments, i.e:
rm SQL.sql* web.tgz*
will replace last 4 lines
-
TY for your tips. I made it that way (password in the script) because I was going to use it as a cron task.
-
If you're going to use it as a cron task, you'll be better off trying to incorporate certificates instead of passwords.
-
Could you explain more? I am too noob in this subject.
-
Actually my bad, that's only if your MySQL server is hosted on another machine. Although you will need to look into a more secure method.
Anyone who is on the box can simple view the process list and see your MySQL root password passed in as an argument.
You're probably better off just backing up the MySQL data files rather than individual databases. That way you don't have to type any passwords in at all.
-
What if you built-in a my.cnf file in your script and piped it to mysqldump, telling mysqldump to read from stdin? Or make a real one.