Showing posts with label backup. Show all posts
Showing posts with label backup. Show all posts

Wednesday, 9 April 2014

Batch / Script to Remove Aged Files

No comments:
Removing aged backup or log files from the windows command line - or by script
Note: 
don't forget if running commands from the command line, the %% syntax becomes a single % (e.g. in the for command) and any environment variables set in the script (e.g. %bkpfolder%) need to be manually set within the command environment where the commands are being manually executed.

Purely date based removal

If you just want to remove files based solely on date, using the forfiles command is and easy awy to go.
The drawback with this is that if there haven't been any backup/log files created  within the aging-period, you can be left with NO files

Refer to MSDN for syntax or type forfiles /? at a windows command prompt

Using forfiles without the /C switch defaults to listing all files matching the /P (path) and /M (mask) criteria using its default /C string of "cmd /c echo @file" - thus:
forfiles /P h:\P6Backup /M *.bak
"20140404-PMDB - Copy.bak"
"20140404-PMDB.bak"
"20140407-PMDB.bak"

Add a /R (reverse) sort if you want the latest at the top of the list....
forfiles /P h:\P6Backup /M *.bak  | sort /R
"20140407-PMDB.bak"
"20140404-PMDB.bak"
"20140404-PMDB - Copy.bak"

using an alternate command string you can use forfiles with the last modified date
forfiles /P h:\P6Backup /M *.bak /C "cmd /c echo @fdate"
7/04/2014
4/04/2014
4/04/2014

combine the /C command line functions to get the info you want
forfiles /P h:\P6Backup /M *.bak /C "cmd /c echo @fdate @file" | sort /R
7/04/2014 "20140407-PMDB.bak"
4/04/2014 "20140404-PMDB.bak"
4/04/2014 "20140404-PMDB - Copy.bak"

Now add the /D switch to only show the files older than -n days from the current date
forfiles /P h:\P6Backup /M *.bak /D -3 /C "cmd /c echo @fdate @file" | sort /R
4/04/2014 "20140404-PMDB.bak"
4/04/2014 "20140404-PMDB - Copy.bak"

Using a slightly altered /C command string to delete rather than display the older files results in the required date-managed elimination of older files
forfiles /P h:\P6Backup /M *.bak /D -3 /C "cmd /c del @fdate"

Retain at-least some files, removing the rest based on their date

To eliminate files based on date but keeping a minimum of n instances regardless of their date, can be achieved using the file looping /f switch of the for command along with the skip parameter

set  %bkpfolder%=P6Backup

REM Del all but the last 3 backups and last 10 logs
  for /f "skip=3 delims=" %%A in ('dir H:\%bkpfolder%\*.bak /a:-d /b /o:-d /t:w ^2^>nul') do if exist "H:\%bkpfolder%\%%A" del "H:\%bkpfolder%\%%A"
  for /f "skip=10 delims=" %%A in ('dir H:\%bkpfolder%\*.log /a:-d /b /o:-d /t:w ^2^>nul') do if exist "H:\%bkpfolder%\%%A" del "H:\%bkpfolder%\%%A"

Refer to Technet or type for /? at the command prompt for the correct for syntax
Refer to Technet or type dir /? at the command prompt for explanation of the switches used in the DIR command within the for loop where we use the atttribute (/a:) switch with it's -d parameter to exclude directories and the sortorder (/o:) switch with it's -d parameter to get the most recent-dated files first. We also use the timefield (/t:) switch with it's w parameter to sort using last-written times and use standard redirection of stderr (standard error) with 2>nul by employing escaped (^) syntax so that the 2>nul redirection of any errors to nul, becomes ^2^>nul








Sunday, 25 March 2012

Start a Skype chat from a shortcut

No comments:
Ever wanted to open a Skype conversation from the command line?
Once you've established the contact, you can reference it as follows:
For example, if you have me automation_man as one of your Skype contacts, you can open a chat session to me from the command line using this syntax
"c:\Program Files\Skype\Phone\Skype.exe /uri:skype:Automation_Man?chat"
Obviously you may need to alter the path to the executable to suit your installation.

Why might you want to do this?
Well in my case, I get my system to send me a Skype message every time it starts, goes into or comes out of standby, or one of it's backup routines finishes
Note that I have found it works more reliably running it from explorer using a utility such as "Runfromprocess.exe"
Copyright: Nir Sofer ( http://www.nirsoft.net)
e.g. the full command lin in my cmd file looks like this:

c:\RunfromProcess.exe explorer.exe "c:\Program Files\Skype\Phone\Skype.exe /uri:skype:Automation_Man?chat"

Using another Nir Sofer command NirCmd, I also send the text to the chat session
NirCmd Sendkey S press
NirCmd Sendkey t press
NirCmd Sendkey a press
NirCmd Sendkey r press
NirCmd Sendkey t press
NirCmd Sendkey P press
NirCmd Sendkey C press
NirCmd Sendkey 1 press
nircmd wait 5000

Then Send the message (ctrl-enter)

NirCmd sendkey ctrl down
NirCmd Sendkey enter press
NirCmd sendkey ctrl up
nircmd wait 12000

Rem Close chat dialog (alt-S-L)

NirCmd sendkey alt down
nircmd wait 500
nircmd sendkey s press
nircmd wait 500
nircmd sendkey l press
nircmd wait 500
NirCmd sendkey alt up
nircmd wait 1000


Rem Add entry to the Application event log
 
eventcreate /l APPLICATION /so "*** NirCmdStart ***" /t INFORMATION /id 997 /d "System Resume Notification - command triggered from scheduled AM/PM events to wake computer"
nircmd wait 500

And audibly announce the system is online

rem 0 = unmute
NirCmd mutesysvolume 0

rem 0 (silence) ~ 65535 (full volume). (32767=half, 16383=quarter)
NirCmd setsysvolume 28000

Rem  Rate of speech between -10 (very slow) and 10 (very fast). volume of the Speech between 0 and 100
NirCmd speak text "P C 01 online now" 1 80

And finally reset the system volume to something respectable
NirCmd setsysvolume 10000

Sunday, 7 August 2011

I like Todo Backup free home version so much ...

1 comment:
REQUEST
I like the free Todo Backup product so much that I will gladly make a contribution for each copy that I use.
Is there some way I could make a donation for each copy I choose to use on my home pc’s?

The old-fashioned idea of being able to fully trial for an unlimited period, then being able to buy single-version copies outright, without having to “subscribe” or “renew” or “regularly upgrade”, suits my needs perfectly.
Your product, however, is so good that I would gladly pay a token amount per copy to support the continued free-access home-use policy.

SUGGESTION
I have two small usability improvement suggestions to offer.
On the Backup tab In the Backup Management dialog where it shows all tasks/plans, it would be great to see the last-run and/or next scheduled time for each task/plan.
I would find this more useful than the Created Time field, currently shown.

Another little bit of feedback was when I started using the product, in that same summary dialog it has the Status column.
To me, “Started” means the backup task is actually performing a backup, though I quickly realised it meant the task was loaded and waiting for the next execution.
Maybe a status of “Scheduled” would be more descriptive?
(e.g. Status’ could be .... Started(or Running); Scheduled(or Pending);Paused)

Thanks for a great product.
Keep up the great work and please keep a “free” (or very cheap) version for other small users like myself – with the option to donate

Regards
Colin J Sanders  Automation Analyst, Dip Elec., MCSE, ITIL, PRINCE
Technology Tamed ®
A.B.N.  13 442 206 580
Blogs:  TechTamed Discussion digital-video-security
Twitter:  @automation_man
Skype:   automation_man