Jump to content
Xandy

Backup Script

Recommended Posts

Xandy

WARNING: I never tried this on a root directory, I should probably write a fix for that case. EX: There is no C:\..\

I don't know how many of these there are on this forum and I know Tidy is real nice for making backups.

I have a few dislikes relying on the Tidy backup:

1 I'm not crazy about the backup folder it creates in project folder.

2. If no Tidy edits are performed script is not backed up on Tidy.  I can't rely on that when I request a backup.

3. If I want to backup a select group of files without backing up the entire project folder, it is somewhat tedious to select each file and Tidy.

 

Now this is just a very simple script that I felt I could use to simplify backing up my project.

I'm not asking you to code it for me, but I welcome feedback.  If you think you can make it better or know of something better please share.

I know of Github it's overkill for me, I'm not comfortable, and I won't use it as much as I need to.

 

So here it is:

You place it in the source folder, open it in Scite.

Change: Global $gBackup_dir_path = "..\Backup\" to wherever you want you backup folder Path to be.

in the main() add some backup("file_name") calls remember to remove file extension.

and it should make a new backup file for each backup("file_name") every time you run the script.

Test it out make sure it's working and you're good to go.

 

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.14.2
    Author:         myName

    Script Function:
    To copy files to a backup folder.

#ce ----------------------------------------------------------------------------

#include <File.au3>

Global $gBackup_dir_path = "..\Backup\"

; Todo
; Add notes, options notes in file name

main()
func main()

    ; File list remember to remove extentions from file_name
    ; or add file extention as second parameter
    backup("Map_Editor")
    backup("DW_Server")

EndFunc

Func backup($spFile_name, $spFile_ext = ".au3")

    Local $error = 0
    Local $iFile_num = 0

    ; Make source file path
    Local $sFile_path_source = $spFile_name & $spFile_ext

    Local $sFile_path_dest = ""

    ; Sample the contents of the backup directory before creating a file there
    Local $aFile = _FileListToArray($gBackup_dir_path, $spFile_name&"*"&$spFile_ext, $FLTA_FILES)
    $error = @error

    If $error = 0 Then

        $iFile_num = $aFile[0]

    EndIf

    out("Found: " & $iFile_num & " files named: " & $spFile_name)

    Do

        ; Incroment file_num to find available file_name
        $iFile_num += 1

        ; Path to Write File Copy
        $sFile_path_dest = $gBackup_dir_path & $spFile_name & "_" & $iFile_num & $spFile_ext

        ; Refuse to Overwrite File
        If FileExists($sFile_path_dest) = 0 Then

            ExitLoop

        EndIf

        ; Am I right?
        Sleep(30)

    Until 0

    ; Create the file
    FileCopy($sFile_path_source, $sFile_path_dest, $FC_CREATEPATH)
    $error = @error

    If $error Then out("FileCopy() error: " & $error)

    out("sFile_path_source: " & $sFile_path_source & " sFile_path_dest: " & $sFile_path_dest)

EndFunc   ;==>backup

Func out($output = "", $user = 0);debug tool

    ConsoleWrite(@CRLF & $output);to console new line, value of $output

EndFunc   ;==>out

Backup_Script.au3

The script isn't authorized to overwrite files, and tries to create the next number of file_name available.

The 'p' in my variable names stands for parameter.

Edited by Xandy
  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • careca
      By careca
      This is a folder backup tool, after i got tired of using tools made by others, that had either lack of functionality,
      or were overly complex, i decided to make my own, and this is it.
      MirrorDir mirrors dirs as the name says, simply select source and destination hit scan, review in the list if that's what you want it to do and press start copy.
      As this is a mirror sync tool, this means files that exist in destination but dont exist in source are marked for deletion.
      Other tools have other modes like the incrementing copy which does not delete anything, but i made this for me,
      only if there is a request i may think about adding features just for fun.
      Whats more? There's a save/load of profile and the profile is what contains the list of source and destination folders, these are kept in prefs.ini in folder MDir in local appdata.
      There are context menu's that allow for the removal of items from the profile list, either just for the list (in case you dont want to sync a specific folder, just this time)
      or delete from the list and the .ini .
      Best regards.
       
       
    • ademon
      By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


    • lenclstr746
      By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
      <snip>
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I found this function in the Internet
      It is to play audio files from  the compiled script
      I did not understand just one thing on this function
      func play($name, $wait = 0) local Const $SND_RESOURCE = 0x00040004 local Const $SND_ASYNC = 1 ; Play the file - the script will pause as it sounds if $wait = 0 then DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC)) else DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", $SND_RESOURCE) endIf return 1 endFunc What I did not understand was this variable
      local Const $SND_RESOURCE = 0x00040004 I know that this variable is contains the resource name
      But what if I want to change the name of the resource what i'll do?
      can i do that?
      Thanks in advance
       
×