LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-05-2014, 02:11 PM   #1
nfurlan
LQ Newbie
 
Registered: Apr 2014
Posts: 10

Rep: Reputation: Disabled
Best FREE way to maintain MySQL backups?


As far as Linux web server emergency plans are concerned, I know that two things are crucial:
  • Keeping backups of website source code (we are currently using Git)
  • Keeping backups of MySQL databases (?)

What is the best free way to keep backups of MySQL databases?

(This is all for a non-profit, and we're trying to keep the costs to a minimum - hopefully at FREE - if possible.)
 
Old 06-05-2014, 02:52 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I use a script and then I move the resulting file.tar.gz to an offsite location.
Script such as:
Code:
#!/bin/bash
mysqldump -u<user> -p<password <web_db_name> > /path/to/file.sql
tar -pczf /path/to/backup/<name_of_archive>_$(date +%F).tar.gz /path/to/file.sql /path/to/site/www/ 
rm /path/to/file.sql
#EOF
Optionally, you may include other key files such as /etc/apache2/sites-enabled/mysite.conf and this very script itself.

Hope that helps.

Last edited by Habitual; 06-10-2014 at 03:06 PM. Reason: s/archive_/archive\>
 
1 members found this post helpful.
Old 06-05-2014, 03:12 PM   #3
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
To add to what Habitual said, you should then copy the backup to another machine or drive (In case the drive fails). Depending on how sensitive and valuable the data is in the database, you might want to back it up off site as well (In case the building catches fire).
 
1 members found this post helpful.
Old 06-06-2014, 05:41 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
You could also consider MySQL replication as well as regular rsync of your website files.

One of the three backup methods / locations that I use for a large forum does this kind of replication and rsync to a Raspberry Pi with a 32Gb SD card that sits beside a network switch at home, not quite "free", but not bad for under $100 for the hardware

If you're interested I'll post the script I use on my production website that can be set to stop MySQL replication, takes a dump with the day name, and rsyncs the backup to an offserver location.

(Oh, and as I'm REALLY, REALLY paranoid about data loss I have my replication slave take an HOURLY backup dump of databases just incase a DROP statement gets replicated!)

Last edited by TenTenths; 06-06-2014 at 05:45 AM.
 
Old 06-06-2014, 11:45 AM   #5
nfurlan
LQ Newbie
 
Registered: Apr 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you all so much for your input!

Do any of you have any ideas on how I could get the .tar.gz MySQL backups to automatically sync to my personal laptop? Would I use rsync? (I figure my laptop, although not a perfect solution, is *free* storage and at least works as a backup)

TenTenths I would love for you to post that script if you have time!
 
Old 06-06-2014, 02:08 PM   #6
nfurlan
LQ Newbie
 
Registered: Apr 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
FYI, I ended up using automysqlbackup on the Linux server, which creates daily and weekly backups of all MySQL databases, and then using the following batch file on my laptop and scheduling it to run daily in Windows Task Scheduler to copy the MySQL database backup folder from the server to my laptop. It'll keep 1 weeks worth (7 copies) of the folder that I'm syncing.

Code:
@echo off
REM Keeps 1 week worth of database backups from server

REM Which day of the week is it?
SETLOCAL enabledelayedexpansion
SET /a count=0
FOR /F "skip=1" %%D IN ('wmic path win32_localtime get dayofweek') DO (
    if "!count!" GTR "0" GOTO next
    if %%D == 1 set dow=Monday
    if %%D == 2 set dow=Tuesday
    if %%D == 3 set dow=Wednesday
    if %%D == 4 set dow=Thursday
    if %%D == 5 set dow=Friday
    if %%D == 6 set dow=Saturday
    if %%D == 7 set dow=Sunday
    SET /a count+=1
)
:next

REM Delete backup from last week
FOR /D %%f in (*%dow%*) DO ( 
    rmdir %%f
)

REM Create directory with today's date and current time
set datetime=%dow%_%date:~-10,2%.%date:~-7,2%.%date:~-4,4%_%time:~0,2%.%time:~3,2%
md "C:\Users\me\Desktop\database_backups\backup_%datetime%"

REM Copy database backups directory to laptop
cd "C:\Users\me\Desktop"
pscp -r -batch -pw mypassword me@999.999.999.999:/backups/* C:\Users\me\Desktop\database_backups\backup_%datetime%
(obviously I changed my IP server's IP address)

Thank you all for your help!
 
Old 06-06-2014, 02:22 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
As long as your engine type is InnoDB, you can use percona xtrabackup which is very tight. If you are using myisam, not so much.

http://www.percona.com/software/percona-xtrabackup

Percona offers a lot in the mysql arena. I've had a couple projects completely leave mysql and switch to percona after seeing the xtrabackup and replication.

Last edited by szboardstretcher; 06-06-2014 at 02:23 PM.
 
  


Reply

Tags
back-up, database, databases, mysql



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: BleachBit - Cleans unnecessary files to free disk space and maintain privacy LXer Syndicated Linux News 1 02-22-2013 12:42 PM
Free remote backups server, HOW?? Ricio Linux - Server 4 11-07-2009 08:26 AM
Mysql table backups Fredde87 Linux - Software 4 12-22-2008 04:55 AM
LXer: Mysql aims to maintain bachelor lifestyle LXer Syndicated Linux News 0 06-30-2006 07:54 AM
Restoring MySQL backups with mysql-administrator pnellesen Programming 0 04-25-2005 09:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration