# Backing up client specific data

**URL:** <https://www.ruby-forum.com/t/backing-up-client-specific-data/130977>\
**Category:** Rails\
**Created:** [March 4, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977 "2008-03-04T22:34:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 4, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/1 "2008-03-04T22:34:39Z")

</div>

This is probably the wrong place to be asking about database  
backups… but this group goes off so:

I have a corporate client that wants their data backed up, and in  
their hands. So, a full database backup and a promise isn’t going to  
cut it, and a full database backup in their hands is bad because we’s  
have to give them everyone elses data!

My first thought was to generate a bunch of CSV files… but the  
database is quite complex and I’d need a separate file for each table.  
That’s fine I guess, but I’m curious if there is a better way?  
Especially if the database often changes.

I’m using MySQL, so does anyone know if there are good tools out there  
that can selectively backup data? can mysqldump do it? how? what about  
mysql administrator?

Thanks

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 5, 2008, 12:46am UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/2 "2008-03-05T00:46:26Z")

</div>

One option might be to create some views specific to the client, and  
just mysqldump those views.

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 5, 2008, 12:54am UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/3 "2008-03-05T00:54:15Z")

</div>

Jonzo wrote:

> I’m using MySQL, so does anyone know if there are good tools out there  
> that can selectively backup data? can mysqldump do it? how? what about  
> mysql administrator?
> 
> Thanks

I like tshim’s suggestion and that is the approach I would take (but  
remember that he is talking about db views and not rails views)

An alternative is to write a simply ruby script that creates another db  
and then does statements like this:  
“create table tempdb.cars as (select productiondb.autos as auto, from autos)”… etc…

hth

ilan

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 5, 2008, 3:27am UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/4 "2008-03-05T03:27:43Z")

</div>

no need to give them access to everyone’s data, you can instruct  
mysqldump to only backup a single database, and then selectively  
choose tables from that database:

mysqldump --user=username --password=password your\_database table1  
table2 table3 table4 -r database\_backup\_`date +"%a_%b_%d_%Y"`.sql

rsync the database to their machine and you’re done

Mike

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 5, 2008, 8:06am UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/5 "2008-03-05T08:06:17Z")

</div>

hey these are all good suggestions! I knew this group was the right  
place to come 😉

unfortunately I can’t use Mike’s because our client data is all mixed  
together…

Thanks everyone 🙂

On Wed, Mar 5, 2008 at 12:54 PM, Ilan B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I like tshim’s suggestion and that is the approach I would take (but
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Jonathan

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 9, 2008, 9:35pm UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/6 "2008-03-09T21:35:28Z")

</div>

Is there something special I need to do in order to backup the data in  
a view without backing up the original table in it’s entirety?

On Wed, Mar 5, 2008 at 8:05 PM, Jonathan F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Wed, Mar 5, 2008 at 12:54 PM, Ilan B.
> 
> > ilan
> 
> –  
> Jonathan

–  
Jonathan

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 5, 2008, 2:43am UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/7 "2008-03-05T02:43:08Z")

</div>

thats probably the simplest idea huh!

Thanks for the suggestion 🙂

On Wed, Mar 5, 2008 at 12:45 PM, tshim [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I’m using MySQL, so does anyone know if there are good tools out there  
> > that can selectively backup data? can mysqldump do it? how? what about  
> > mysql administrator?
> > 
> > Thanks

–  
Jonathan

---

<div class="post-metadata">

**Author:** ![jonzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jonzo](https://www.ruby-forum.com/u/jonzo)\
**Post date:** [March 9, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/backing-up-client-specific-data/130977/8 "2008-03-09T23:25:43Z")

</div>

Just a follow up - I ended up using Ilan’s suggestion:

- create a new database
- generate the content with queries from the original database
- run mysqldump
- delete the database

I did this all from within rails! I’m pretty happy with the solution  
now because it means that I can generate the backups through the web,  
or with cron jobs, and that the generated files can then be downloaded  
by admins or by the clients themselves. We probably won’t let that  
happen though because it’d be giving away our db design…

I also tried out creating views but there are several reasons why I  
didn’t carry on:

- I couldn’t find a way to pass variables into a view (this is more  
of a stored procedure thing), so I had to hard code the account id  
into one view, and base the rest of the views on that.
- they views are stored in the same original database, so I would end  
up with ~8 new tables/views for each client that wants to have  
backups.
- when I tried to use mysql dump with them it didn’t dump the data.  
I’m not sure if there is a way around this but it wasn’t easy to find  
if there is.
- the view names would need to be different from the original table  
names, this means that if the time came for the db to be regenerated  
from a backup, it’d be more difficult than it needs to be.

I hope my experiences help someone else out!

Once again, thanks for all your help everyone.
