Help for File Backup Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
kadhri
Posts: 49
Joined: 12 Nov 2015, 06:52

Help for File Backup

05 Nov 2017, 06:25

I have to make file backups every day
so i made a script like this

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
Gui, Add, Edit, x32 y60 w190 h20 vSOURCE, 
Gui, Add, Text, x32 y40 w90 h20 , Recording Source
Gui, Add, Edit, x32 y100 w190 h20 vDESTINATION, 
Gui, Add, Text, x32 y80 w90 h20 , Destination
Gui, Add, Button, x232 y60 w70 h20 gSRC, Browse
Gui, Add, Button, x232 y100 w70 h20 gDEST, Browse
Gui, Add, Edit, x32 y140 w110 h20 vUSER, 
Gui, Add, Text, x32 y120 w90 h20 , User ID
Gui, Add, Button, x152 y140 w70 h20 gDOWNLOAD, Download
Gui, Show, x215 y232 h184 w340, 
Return

GuiClose:
ExitApp
Return

SRC:
FileSelectFolder, server
GuiControl,,SOURCE,%server%
Return

DEST:
FileSelectFolder, dest
GuiControl,,DESTINATION,%dest%
Return

DOWNLOAD:
GuiControlGet,USER
IfExist, %server%\2017-08-09\%USER%
FileCreateDir,%dest%\%USER%\AUG 09\
FileCopy, %server%\2017-08-09\%USER%\*.* , %dest%\%USER%\AUG 09\
Return
this works fine
I need help for these tasks
1: if user folder found and copy was done , then go to next date ie 2017-08-10, and repeat the task, i want it to run for all the 31 days of august
2: if given user folder data not found in the 2017-08-09 , log into a text file and go for next date ie 2017-08-10

is there any better/automatic way for doing this
awaiting for responce

Thanks for your great help in advance
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Help for File Backup  Topic is solved

05 Nov 2017, 12:34

If you want to keep it simple and have it hard coded for August, you can use a Loop on your download routine:

Code: Select all

DOWNLOAD:
GuiControlGet,USER
Loop, 31
{
day:=SubStr("0" . A_Index,-1) ; -1 captures the second to last character, 0 captures the last character. The string will be 01, 02 ... 09, 010, 011.... So we want the last 2 characters each time. It's just a way to pad the single digits with a 0
IfExist, %server%\2017-08-%day%\%USER%
FileCreateDir,%dest%\%USER%\AUG %day%\
FileCopy, %server%\2017-08-%day%\%USER%\*.* , %dest%\%USER%\AUG %day%\
}
Return
You can get more complicated if you wanted to expand this beyond August. Otherwise, you'd need to change the number of loop for each month. Unless you're OK with checking for dates like September 31st or February 30th which simply don't exist, becuae the "IfExist" should fail.

However, a potential oversight in your code - I'm not sure if it really is - is your IfExist only affects the FileCreateDir. No matter what, all File Copies are done. So if the file doesn't exist on 2017-08-09\%USER%, FileCopy will still attempt to copy that directory. You may want to wrap the FileCreateDir and FileCopy in a Block together using the { and }, like I did with the Loop.

OK, now, as for the logging task. This can be done with an Else statement that comes after the suggested Block above. (Without the Block, the Else needs to come before the FileCopy). You can use FileAppend to add onto a log.txt file. Remember to add a "`n" character (newline) or "`r`n" (carriage return and new line) at the start or end of each log entry so that you don't get a jumbled one-line mess.
kadhri
Posts: 49
Joined: 12 Nov 2015, 06:52

Re: Help for File Backup

08 Nov 2017, 06:41

Thanks Exaskryz, you are the life savour
Yes, I have modified my script with your suggestions,
Now I am extending my script to copy date wise filecopy and month wise copy, I have added one GUI MonthCal control
If select a date then it should copy that dates data to destination.
Now my question is how do select month and dates from month control and store in to variable?

Regards,
Kadhri
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Help for File Backup

08 Nov 2017, 08:13

Just an example on how to get the choosen date from control

Code: Select all

Gui, add, MonthCal, vCal gCalsub
Gui,Show
return

Calsub:
   MsgBox % "Choosen date :" Cal "`nYear " substr(cal,1,4) "`nMonth " substr(cal,5,2) "`nDay " substr(cal,7,2)
   
return

GuiClose:
GuiEscape:
   ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
kadhri
Posts: 49
Joined: 12 Nov 2015, 06:52

Re: Help for File Backup

08 Nov 2017, 11:06

Thanks Odlanir, all my doubts are sorted out now
kadhri
Posts: 49
Joined: 12 Nov 2015, 06:52

Re: Help for File Backup

10 Nov 2017, 13:30

Hi all,
While extending my script further I struck here
1. I have to search for multiple user files one by one
So, I want to extend it like this , if I select a text file which contained a list of users, loop users and done the job

2, how can I distinguish the loop for months having 30 days and 31 days and February

3. I am showing traytip while copying files ( using else), While copying all files for the current momth, stop showing if loop retrieves current day

BTW, I am sys admin, my programming skills are poor, working for call center environment.
Once again special thanks to Exaskryz, Odlanir
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help for File Backup

10 Nov 2017, 14:44

Code: Select all

q:: ;dates - get number of days in month
;start with a 6-digit month (yyyyMM)
vDate := SubStr(A_Now, 1, 6)
;vDate := 201702
;vDate := 201712

vDate += 32, Days
vDate := SubStr(vDate, 1, 6)
vDate += -1, Days
vDays := SubStr(vDate, 7, 2)
MsgBox, % vDays
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
kadhri
Posts: 49
Joined: 12 Nov 2015, 06:52

Re: Help for File Backup

11 Nov 2017, 13:27

Thanks @jeeswg, solved the 2 and 3 queries, still a stuck at 1one, I need to search around 200 user files in folders created by name in date was folders, that are stored in backup server
My scripts works great while searching for one user, I want to extend it further
Anyone please provide me idea or logic how to achieve it
Is loop, parse will work?

Thanks in advance
Kadgri
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Help for File Backup

11 Nov 2017, 19:12

I'm not sure if this is the answer you're looking for, but Loop, Files can read all the subfolders and files in a directory?
kadhri
Posts: 49
Joined: 12 Nov 2015, 06:52

Re: Help for File Backup

12 Nov 2017, 03:48

Thanks to you for this
https://autohotkey.com/board/topic/1218 ... ers-msgbox
Dear @Exaskryz, you only answered the above question, this is what I really wants to do :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], HiSoKa, Kainie, mikeyww, nabbott22, Terka and 54 guests