Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • automated do file backup

    When I save a do file I want to save it to the specified location and then also save a backup to one standard location for all do files, both on a server and my local machine. I found this post to a script on github that seems like it would get the job done, but getting this program up and running on my machine probably isn't an option for me. Any guidance or suggestions on alternative ways to accomplish this would be greatly appreciated, or maybe this would be a suggested addition for a future version of Stata?

  • #2
    Surely there are many ways one can envision to do this type of task, to the point where you may not receive helpful answers. Perhaps you can share what kind of platform you are running Stata on (is it Windows, Linux or Mac? Network or local?) and what rights you have (can you install programs? do you have an IT department that can do that?).

    For me, I'm a fan of using git precisely because I must consciously choose what and when I commit. I often commit daily/nightly work as well so that I capture work-in-progress. You could set up a remote git repository even within your own network, but that depends on your workplace policies and level of IT support.

    On the other side, if you can schedule a batch job on your own machine, then that should be enough to write a script that copies files on a periodic basis, similar to the linked github file. The catch is that you would need to write such a script yourself (or find someone who can).

    Comment


    • #3
      Thanks for the reply, Leonardo.

      I'm working on a Windows machine. Our IT department is less than helpful on these topics and permissions to install new programs often take a long time, if approval ever even happens, so that's not a reliable direction. I think my agency is trending towards writing such a script, but I don't have that skill set yet and don't know when they'll get to it. I thought maybe somebody knew of an online resource with a step-by-step process.

      Comment


      • #4
        You could use the portable version of Git and set up a local repository for your do-files. See https://github.com/sheabunge/GitPortable for how to set up a portable Git installation. If you are familiar with the command line then you usually need only a few commands in your daily work. These commands could become part of a script which you run daily or however often you want it to run.
        Code:
        git init // run only once in the base directory where you want to have your local repository -> could be the same directory as your directory with the do-files.
        git add *.do // add all do-files in the current directory
        git commit -a -m "<your commit message here>" // alternatively an editor will open if you leave out the "-m"  to type in longer commit messages
        Git for Windows comes also with a GUI but I am not really familiar with it. There are other GUIs but I don't know if they work in a portable setup.

        Comment


        • #5
          The suggestion for a portable Git installation is a good one. I did not know there was a portable version, so thank you for pointing that out.

          Comment


          • #6
            I have not tried it out myself. I just saw when I was looking for a solution to Michael Weinerman problem.

            Comment


            • #7
              This doesn't exactly solve your problem, but I include a line of code at the top of each do-file which copies that dofile, with a time/date stamp appended, to a standard location. This makes a copy every time the do-file is *run*, but not every time it is saved.


              Comment


              • #8
                Sven-Kristjan Bormann: thanks for the git idea and code. I'll see if this is something we can implement.

                Jeph Herrin: Thanks, I hadn't thought of that. I found discussion about why saving a do file from within the do file is prohibited, which makes sense, but just making a copy when it is run will be a nice immediate solution while we work on something more permanent. For anybody interested, the code I'm posting below is adopted from the discussion found here.

                Code:
                local today: di %td_N-D-CY date(c(current_date),"DMY")  
                copy "my do.do" "[backup folder path]my do`today'.do", replace
                Last edited by Michael Weinerman; 20 Mar 2020, 11:23.

                Comment

                Working...
                X