Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Macros, Scripts, and Formulas Repository
 PowerHome Messageboard : PowerHome Macros, Scripts, and Formulas Repository
Subject Topic: auto Backup & Trim PH db files Post ReplyPost New Topic
Message << Prev Topic | Next Topic >>
Super User
Super User

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 935
Posted: June 19 2013 at 07:30 | IP Logged Quote GadgetGuy

It is a good practice to use the PH database backup function to periodically save your PH conditions, using the   "ph_backupdb" function.

I automatically run this function every night using a Timed Event. To keep the backups distinct (rather than writing over the last one) I append a date string to the file name.

The construct looks like this . . .
ph_backupdb("C:\powerhome\Database\dbAutoBaks\PH-"+string(to day(),"yymmdd")+".db",0)
/* Backup PH database file */.

Where I have created a folder called "dbAutoBaks" within the PowerHome/Database folder.

The saved db file names look like this "ph-130619.db"

To manage the buildup of files that would occur over time I wrote a VB .Net program to trim the db files in the folder to 30 days worth.

I run this in the same Timed Event sequence that does the backup.

This ph formula calls my compiled fileTrim executable . . .

Here is the VB program so that you can customize it to fit your environment. This is run as a Windows Forms Application . . .

This was written in VB .Net 4.5, but I believe will run on from 2-4.5.


Imports System
Imports System.IO
Imports System.Security.AccessControl

Public Class phFileTrim

    Private Sub fileTrim_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim text As String
        Dim UserAccount As String = "Admin"
        Dim intdays As Integer = 30
        Dim filePath As String = "C:\powerhome\Database\dbAutoBaks"
        Dim fi As IO.FileInfo = New IO.FileInfo(filePath)

        For Each fi In New IO.DirectoryInfo(filePath).GetFiles("*.*")
                If (Now - fi.CreationTime).Days > intdays Then
                     fi.IsReadOnly = False
                End If
             Catch ex As Exception
                text = "File Delete Failed: " & ex.ToString
             End Try
    End Sub
End Class

Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum