Differential backup of files / folders when they are changed or on schedule

Get help with using AutoHotkey and its commands and hotkeys
loek6000
Posts: 36
Joined: 14 Aug 2019, 17:46

Differential backup of files / folders when they are changed or on schedule

05 Aug 2020, 11:31

I used different sorts of programs to do a backup, but i don't really like the most of them.

I would like to backup some files which are important to me. I would also like to keep several copies of these files while i change these files on a regular basis (like autohotkey files)

I know xcopy and robocopy can do these jobs with scripts, but they output a cmd box most of the times.

Is there a way that (for example) filecopy (from autohotkey) look for a file that is already there, do a copy (like sample.ahk -> sample_copy01.ahk) and any other attemt that i change that file it will copy with only increasing numbers (copy01, copy02, copy03.......)

Hopefully i am clear enough while explaining, english is not my 1st language :)
loek6000
Posts: 36
Joined: 14 Aug 2019, 17:46

Re: Differential backup of files / folders when they are changed or on schedule

05 Aug 2020, 12:04

I already found something i was somewhat looking for. 1 thing tho, i would like to make a backup once a file has changed (like it monitors file changes)


credits go to ..Laszlo @ https://autohotkey.com/board/topic/5407-copyifnewer-incremental-backup/

Code: Select all

dir_source = c:\btest 
dir_backup = c:\backup 
FormatTime dir_bb,%A_NowUTC%,yy.MM.dd-HH.mm.ss 
FileCreateDir %dir_backup%\%dir_bb% 

Loop %dir_source%\*.* 
{ 
   IfExist %dir_backup%\%A_LoopFileName%
   {
      FileGetTime sourceTime, %dir_source%\%A_LoopFileName%
      FileGetTime backupTime, %dir_backup%\%A_LoopFileName%
      IfEqual sourceTime,%backupTime%, Continue
      FileMove %dir_backup%\%A_LoopFileName%, %dir_backup%\%dir_bb%\%A_LoopFileName% 
   }
   FileCopy %dir_source%\%A_LoopFileName%, %dir_backup%\%a_LoopFileName% 
} 

FileRemoveDir %dir_backup%\%dir_bb%
loek6000
Posts: 36
Joined: 14 Aug 2019, 17:46

Re: Differential backup of files / folders when they are changed or on schedule

05 Aug 2020, 12:19

Ok i changed it a bit, tho it doesnt copy new made folders into the backup folder... how to do that?
Also: i would like to backup multiple folders (sources, so not only the btest folder)
I added these:

Code: Select all

dir_source = c:\intel\btest
dir_source = c:\intel\x
dir_backup = c:\intel\backup
but all the source files are dropped in 1 folder, is there a 'nicer' way?

suggestions are welcome:

Code: Select all

#Persistent
Settimer,Loopme,6000
LoopMe:
dir_source = c:\intel\btest 
dir_backup = c:\intel\backup 
FormatTime dir_bb,%A_NowUTC%,yy.MM.dd-HH.mm.ss 
FileCreateDir %dir_backup%\%dir_bb% 



Loop %dir_source%\*.* 
{ 
   IfExist %dir_backup%\%A_LoopFileName%
   {
      FileGetTime sourceTime, %dir_source%\%A_LoopFileName%
      FileGetTime backupTime, %dir_backup%\%A_LoopFileName%
      IfEqual sourceTime,%backupTime%, Continue
      FileMove %dir_backup%\%A_LoopFileName%, %dir_backup%\%dir_bb%\%A_LoopFileName% 
   }
   FileCopy %dir_source%\%A_LoopFileName%, %dir_backup%\%a_LoopFileName% 
} 

FileRemoveDir %dir_backup%\%dir_bb%
loek6000
Posts: 36
Joined: 14 Aug 2019, 17:46

Re: Differential backup of files / folders when they are changed or on schedule

06 Aug 2020, 04:40

I think this would be a simple thing to add, but i don't know it, maybe some help?

I would like to have multiple folders to be backed up and includes the folders within these folders (not only the files)

the working code i got now is:

Code: Select all

#NoTrayIcon
#Persistent
#SingleInstance, force
Settimer,Loopme,600000

LoopMe:
dir_source = D:\Tools\Data\Autohotkey
dir_backup = \\LIBREELEC\rootfs\home\PCBackup\Autohotkey

FormatTime dir_bb,%A_NowGMT%,yyyy.MM.dd-HH.mm.ss 
FileCreateDir %dir_backup%\%dir_bb% 

Loop %dir_source%\*.* 
{ 
   IfExist %dir_backup%\%A_LoopFileName%
   {
      FileGetTime sourceTime, %dir_source%\%A_LoopFileName%
      FileGetTime backupTime, %dir_backup%\%A_LoopFileName%
      IfEqual sourceTime,%backupTime%, Continue
      FileMove %dir_backup%\%A_LoopFileName%, %dir_backup%\%dir_bb%\%A_LoopFileName% 
   }
   FileCopy %dir_source%\%A_LoopFileName%, %dir_backup%\%a_LoopFileName% 
} 

FileRemoveDir %dir_backup%\%dir_bb%
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Differential backup of files / folders when they are changed or on schedule

08 Aug 2020, 03:52

I can currently not help you on your specific issue, but I remember a script that watched a folder for changes. You might be interested in case you want some automatic solution instead of manual or fixed times of backup. I assume you should be able to find the script in the script section with “watch folder”
ciao
toralf
DaveT1
Posts: 83
Joined: 07 Oct 2014, 11:23

Re: Differential backup of files / folders when they are changed or on schedule

08 Aug 2020, 04:34

I wrote an AHK script to do backups of files (and allowed notes be to added for changes), but it was manually triggered rather than being automatically fired. However it always irked me that the backups were copies of the whole file, rather that just the changes to the file since the last backup.

I eventually gave in and now use TortoiseSVN to allow the increments to be comitted, saving in a local repository. It has a ton of stuff I don't understand / will never need, but it's been a useful thing to at least learn the basics. It is still manually fired though.

HTHs.
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Differential backup of files / folders when they are changed or on schedule

08 Aug 2020, 04:51

I use github desktop client to backup my scripts locally, and also use github for remote backup
ciao
toralf

Return to “Ask For Help”

Who is online

Users browsing this forum: aifritz, Bing [Bot], boiler, Google [Bot], mikeyww and 34 guests