1

I want to take back-up copy of my network dirs once in a day on specified time, Below is the code of my current work by which i am running it manually.

So i want to do this manual work as windows service which creates a back-up copy of specified network dir on particular time.

import tarfile
import datetime

def backup_htmls():
    tar = tarfile.open('./InputHTML_bc/'+datetime.datetime.now().strftime('%b_%d_%Y_%H_%M_%S')+".tar.gz", "w:gz")
    tar.add('\\\\192.168.211.65\\shared\\InputHTML\\', arcname="Backup_Tar")
    tar.close()

I have the reference of how to run it as a windows service;

i just want how can i run this job once in a day on particular time(for example if i pass time as a parameter to python function and it will execute it once for that day.. or any other way you can do it.. in pythonic way)??? i know it will be very easy but i am not getting the idea from where i can start anyway of doing it???

namit
  • 6,780
  • 4
  • 35
  • 41
  • 2
    No need for a service, just use the [windows scheduller](http://windows.microsoft.com/en-US/windows7/schedule-a-task). – Paulo Scardine Sep 21 '12 at 08:41
  • 1
    If you are on a linux environment, use cron job to run it once a day at a specific time. – ronak Sep 21 '12 at 08:43
  • @ronak: from the OP question: i want to run it as a service on windows – Paulo Scardine Sep 21 '12 at 08:45
  • I know the reference of how to run it as a service; i just want how can i run this job once in a day on particular time??? i know it will be very easy but i am not getting the idea from where i can start – namit Sep 21 '12 at 10:47
  • 1
    Use `r''` literals to avoid using so many backslashes: `r'\\192.168.211.65\shared\InputHTML'` – nneonneo Sep 21 '12 at 10:50

2 Answers2

1

Here's a recipe that shows you how to create a windows service using Python:

http://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/

Fabian
  • 4,160
  • 20
  • 32
0

There is this: http://runasservice.sourceforge.net/

Which was referenced in this similar question:

Run batch file as a Windows service

And as a batch file can start your python up....

Community
  • 1
  • 1
Paul Collingwood
  • 9,053
  • 3
  • 23
  • 36