cancel
Showing results for 
Search instead for 
Did you mean: 

backups

Tonyr
Newbie
Posts: 8
Registered: ‎31-03-2010

backups

I know that I should have done it sooner rather than pray to the great god of backup for forgiveness after the event! Well I think I might have caught this one in time if you can help?
I need to backup all the files I have on the CGI server, some are php but there are a load of uploaded photographs as well. In addition I need to backup the data held in MySQL. The question is what is the best tool for the job. I would have used the SSH login if it was available but since that is no longer an option, any ideas?
4 REPLIES 4
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: backups

Hi Tony,
I guess backing up the db you'd still do using phpmyadmin export tab at https://mysql.plus.net/
For the rest, no login, but you can run non-interactive shell scripts like
#!/bin/bash
echo "Content-type: text/plain"
echo
tar -cvvzf foo.tar.gz foo/

(tar.cgi upload as ascii and set mode 0700 then request in browser) would pack up your foo folder into foo.tar.gz and
#!/bin/bash
echo "Content-type: text/plain"
echo
tar -xvvzf foo.tar.gz

would unpack it again. Down/upload and delete using ftp. Not most elegant but works.
Gabe
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: backups

You could do something like this in a similar vein, but includes the mysql databases and emails the finished file to you.

#!/bin/bash
echo "Content-type: text/plain"
echo
# Add in your mysql details here
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DATABASE=
# Add in your email address
EMAIL=
BACKUPFILE=backup.tar.gz
DATE=$(date +'%Y-%m-%d')
BOUNDARY=$DATE/backup+++
cd ~
mysqldump --opt -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE > $MYSQL_DATABASE.sql
tar -cvf - . | base64 > $BACKUPFILE.base64
rm $MYSQL_DATABASE.sql
cat <<EOF> $BACKUPFILE.head
From: <$EMAIL>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="$BOUNDARY"
This is a multipart message in MIME format.
--$BOUNDARY
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Please find backup.tar.gz attached
--$BOUNDARY
Content-Type: application/octet-stream; name="$BACKUPFILE"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="$BACKUPFILE"
EOF
cat $BACKUPFILE.head $BACKUPFILE.base64 | mailx -s "Daily backup for $DATE" $EMAIL
rm $BACKUPFILE.head $BACKUPFILE.base64

I've just knocked this up off the top of the head so it might need some tidying and testing, but it should work,
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: backups

Quote from: Ben
I've just knocked this up off the top of the head

And remembered to base64 the thing on a Friday afternoon.  Cool
Gabe
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: backups

Duly deFridayed and tested a bit:
#!/bin/bash
echo "Content-type: text/plain"
echo
# Add in your mysql details here
MYSQL_HOST=
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DATABASE=
# Add in your email address
EMAIL=
# Select files to backup
# . backs up everything
# or select files and folders
# between quotes, e.g.:
# "mysql_backup.sql wordpress/wp-content/ foo.txt bar/foo.txt"
BACKUPFILE="mysql_backup.sql"
# Nothing more to add
DATE=$(date +'%Y-%m-%d')
cd ~
mysqldump --opt -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE > mysql_backup.sql
cat <<EOF> tmpfile.txt
To: $EMAIL
From: $EMAIL
Subject: Backup on $DATE
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=$DATE-backup
--$DATE-backup
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
See attached.
--$DATE-backup
Content-Type: application/x-tgz
Content-Disposition: attachment; filename=backup.tar.gz
Content-Transfer-Encoding: base64
EOF
tar -cvzf - $BACKUPFILE | base64 >> tmpfile.txt
cat <<EOF>> tmpfile.txt
--$DATE-backup--
EOF
cat tmpfile.txt | /usr/sbin/sendmail -t -i
rm tmpfile.txt mysql_backup.sql
echo "Backup sent to "$EMAIL

Gabe