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

    • tintin92
      By tintin92
      Hello,

      How can I automatically download a list of zip files, like the ones in the quote, using a AutoIt script?
      Is it possible with AutoIt script?
       
    • Marc
      By Marc
      Profiler - yet another backup script for Firefox and Thunderbird profiles
      It automatically detects the last recently used profile directories of Firefox and Thunderbird (installed versions, no portables).
      Clicking the Backup-Button creates a complete Backup of the found profiles with a timestamp.
      Restore deletes the according profile dir and extracts the content of the selected archive into the profile directory.
      Uses Winrar as compression tool, but feel free to change it to your needs
      Best regards
      Marc

      Profiler.au3
    • Eggsplorer
      By Eggsplorer
      Hi,
      Ich hab ein Script für Windows Updates, dass nach dem OOBE aufgerufen werden soll. Run/RunOnce ist daher nicht möglich.
      Stattdessen möchte ich das Script in den Autostart schreiben lasse. Wenn die OOBE beendet wird und der Administrator angemeldet wird, soll das Update-Script einmalig aufgerufen werden und sich anschl. selbst löschen.
      Lang rede, kurzer Sinn:
      Wie kann ich folgendes Script in den Autostart schreiben?
      RunWait(@ComSpec & " /c " & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\UA\Scripts\win-updates.ps1 -MaxUpdatesPerCycle 100 -RestartRequired 1", "") Ich würde ungern eine BAT oder EXE reinkopieren, da ich es unsauber finde. Die müsste ja auch zusätzlich irgendwo liegen.
      Danke
      Eggsplorer
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.