• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Archiving data in a MySQL DB

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Archiving data in a MySQL DB

    Say I have a DB set which holds results and other info about my customers.

    This info changes over time and I want to take regular snapshots and compare the changes. An example would be:

    Customer_a signs up and I take a snapshot of certain things about their website. This goes into a table

    Then each week I want to take the same snapshot but the data will have changed. I'd like to keep each snapshot and be able to do comparisons and generate reports.

    Do I need a new table for each weekly snapshot or is there a cleverer/more efficient way to just have the snapshot data in 1 table and archive the historical ones?

    I'll be using PHP as the reporting interface.
    "Is someone you don't like allowed to say something you don't like? If that is the case then we have free speech."- Elon Musk

    #2
    Creating new tables for each week sounds like a bad idea to me. I don't see any reason why you couldn't copy the snapshot to an archive table before you update it in the original table. You could add a timestamp to the archived copy so you know the date that copy is from.

    Comment


      #3
      Is there any particular reason not to just create a new record per customer per week, with a timestamp on it? Storage is dirt cheap these days, after all. At some point in the future you can archive the old data, but it might make more sense to do that on a rolling basis so you've always got the last n months data readily accessible.

      Comment


        #4
        Originally posted by NickFitz View Post
        Is there any particular reason not to just create a new record per customer per week, with a timestamp on it? Storage is dirt cheap these days, after all. At some point in the future you can archive the old data, but it might make more sense to do that on a rolling basis so you've always got the last n months data readily accessible.
        That was my first thought too. Copying them to a separate archive table would keep the main table cleaner but apart from that I can't see any benefit.

        Comment


          #5
          I'd go with NickFitz's idea and archive every few months.
          +50 Xeno Geek Points
          Come back Toolpusher, scotspine, Voodooflux. Pogle
          As for the rest of you - DILLIGAF

          Purveyor of fine quality smut since 2005

          CUK Olympic University Challenge Champions 2010/2012

          Comment


            #6
            Originally posted by NickFitz View Post
            Is there any particular reason not to just create a new record per customer per week, with a timestamp on it? Storage is dirt cheap these days, after all. At some point in the future you can archive the old data, but it might make more sense to do that on a rolling basis so you've always got the last n months data readily accessible.
            This is what I'm trying to achieve, a new record with a timestamp.

            Pardon my ignorance - but where would this record be stored? This isn't covered in "PHP & MySQL for Dummies" (yes I have read it )
            "Is someone you don't like allowed to say something you don't like? If that is the case then we have free speech."- Elon Musk

            Comment


              #7
              It sounds like what you need to do is:

              1. Add a new column to the table, call it timestamp or whatever
              2. Change the UPDATE statement you're using at the moment to an INSERT, so instead of overwriting the previous data, it creates a new row. Also, remember to add the timestamp to the INSERT.
              3. You'll need to change your SELECT for getting the snapshot out of the DB to make sure it uses the most recent snapshot in the table for that customer.

              Comment


                #8
                Originally posted by Jog On View Post
                This is what I'm trying to achieve, a new record with a timestamp.

                Pardon my ignorance - but where would this record be stored? This isn't covered in "PHP & MySQL for Dummies" (yes I have read it )
                It would be stored in the same table currently used for the snapshots.

                Comment


                  #9
                  Thanks. I'd never heard of records until now, can I give an example of what I'm trying to accomplish:

                  One such snapshot I want to take is how many websites link to a particular site. I'll make a table for this called 'backlinks' and it will have columns:

                  customer - this will only have 1 entry in the table
                  Customer URL - this will only have 1 entry as well
                  date - again only 1 entry
                  backlinks - this could run into hundreds of thousands of rows


                  I will want to update this table every week, so would I just amend the new data and add a timestamp to the record? From what I've read a record is just a single row - is this right?

                  Lets say one week a site has 120 backlinks then a month later it has 400 I'll want to be able to chart this over the 4 weekly updates. Will the records do this for me?

                  I'd love some reading on this but I don't think I'm googling the right terms
                  "Is someone you don't like allowed to say something you don't like? If that is the case then we have free speech."- Elon Musk

                  Comment


                    #10
                    Ah, slight misunderstanding I think. A record is just another name for a row. There's nothing special about it. We're just talking about creating each row with a timestamp so you can have multiple copies of them in the same table. If each "snapshot" consists of data spread across several rows in several tables it gets a bit trickier, but not impossible.

                    Comment

                    Working...
                    X