Run batch file each time a specific file is saved - batch-file

I have a shared Excel file on a network, and I want to create a backup each time the file is saved in case it gets overwritten or deleted by mistake.
I created a batch file to save a backup of the file with timestamp in the filename (found it here:https://datatofish.com/backup-file-timestamp/).
Now I'm looking for a way to trigger the batch file each time the file is saved so I will have a history of all the changes and backups in case of a problem. Is there a simple way to do that? Maybe using Task Scheduler? I've never used Task Scheduler so I would need a detailed description.
Thanks.

Related

Cmd prompt for restoring files

I have a few power automate flows that rely on word documents that have been setup. However, my flow keeps breaking because with the company’s retention policy, the file is automatically deleted every few days. I have to go to the recycle bin to find the doc to restore and resubmit the flow.
I created a .bat file and linked to scheduler to run daily to check if the file is there, and if not to copy it to the folder from one of the permanent folders. However the flow still breaks because it doesn’t auto link the file again. It does link when I manually restore from deleted items. Can’t redirect the flow to permanent folder either. So easiest would be to update bat file to restore from recycle bin.
Currently it’s
IF NOT EXIST C:\users\’flow folder’ copy “g:\perm folder” “c:\flow folder”

Can you backup cached memory of an open file using Shadow Copy (VSS)?

If I wanted to create a backup of a MS Word document that was open, I would need to close the file before any backup was possible. With Shadow Copy, I can backup an open file, but would the unsaved changes be backed up with the snapshot of the Word document?
I am trying to create a program that automatically creates backups of file(s) using Shadow Copy (VSS). I already have the Windows Task Scheduler setup but need the batch file for execution. However, I cannot seem to understand how to create such a batch file so that I can create a backup of an open file by Shadow Copying it onto another drive.
This is for personal/basic use. I cannot grasp at how to backup the unsaved information that would be "cached" in an open MS Word document. Is this even possible?
Thank you for your time.

how to replace flat file created by a export data wizard on a schedule task with server agent

i already create a SSIS package on SSMS and scheduled in Server Agent, it create succesfully my '.csv' file but i want to overwrite the file every night when the scheduled job start again.
In your SSIS package, in the Flat File Destination, make sure the box Overwrite data in the file is checked. When the package runs each night, the file will be overwritten with new data.
Use a File System Task in your Control Flow.
The File System task performs operations on files and directories in
the file system. For example, by using the File System task, a package
can create, move, or delete directories and files. You can also use
the File System task to set attributes on files and directories. For
example, the File System task can make files hidden or read-only.

Concatenate TimeStamp to File using Batch file

I have created two batch file that are working. Here is the outline
First Batch Calls another batch file
The second batch file changes to the directory on the application where the utility and command path to backup an asset resides, does the backup and places the file in C:\
I simple did a cd/ after the CALL command used to start second batch file to return to the path where the backup file is archived.
How do I use
set backupFilename=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
or other function to Concatenate to the backup file?
FileName_05-21-2015:09:30 Pm.txt
I am getting an error that the file does not exist when in fact it does. My intention is to use AT command or Schtask command to schedule this backup process every week. I will also appreciate more descriptive application of this commands too with time stamp for every backup completed on schedule

SQL Server script to read many csv files at certain intervals and insert records

I have some csv files. I want to write SQL Server script to read the file at certain period and insert in SQL Server db, if record is not found and ignore it if file has already been read previously by scheduler. Each csv will contain one record only.
Like:
1.csv => John,2000,2012/12/12
2.csv => Tom,3000,2012/12/11
It will be great if someone can provide examples of script.
Thanks!
If I was you I would create an SSIS package that uses the multi file input. This input let's you pull data from every file in a directory.
Here are the basic steps for your SSIS package.
Check if there are any files in the "working" directory. If not end the package.
Move every file from your "working" directory to a "staging" directory.
You will do this so that if additional files appear in your "working" directory while you are in the midst of the package you won't lose them.
Read all of the files in the "staging" directory. Use a data flow with the multi file input.
Once the reading has been completed then move all of the files to a
"backup" directory.
This of course assumes you want to keep them for some reason. You could just as easily delete them from the "staging" directory.
Once you have your package completed then schedule it using SQL Server agent to run the package at whatever interval you are interested in.

Resources