Sign in to follow this  
Followers 0
magus

Auto-Backup MS Office Documents with DropBox

2 posts in this topic

#1 ·  Posted (edited)

One day, software such as this will make it possible for us to live in a world in which documents are NEVER lost! Everyone's documents will be automatically backed up whenever they are modified. It's a completely automated process.

Digg: http://digg.com/gadgets/DIGG_THIS_Auto_bac...ments_w_DropBox

The compiled program is ready to go out of the box, once DropBox has been installed.

Program: Auto_DropBox.exe (updated)

;Written by magus.from.chrono.trigger@gmail.com

;Description: This script will automatically back up every instance of certain filetypes. It will run continuously check for newly modified files in the background, however it will only re-index the host computer when it has been idle for a certain amount of time.
;Requirements: DropBox : http://www.getdropbox.com/

#RequireAdmin
#Include <File.au3>
#Include <Date.au3>
#include <Timers.au3>

Opt("TrayIconDebug", 1)

;------------------Preferences----------------
$idle_time_in_minutes = 60;amount of time since last user activity (i.e. KYBD/Mouse) necessary before re-indexing may begin.
$auto_backup_cycle = 1;delay to be distributed evenly amongst the tasks to be completed during each auto-backup cycle, in minutes. Increase this if the script slows your computer down.
$max_size_in_MB = 20
$extension_list = "pdf txt rtf doc docx docm dotx dotm xls xlsx xlsm xltx xltm xlsb xlam ppt pptx potx potm ppam ppsx ppsm sldx sldm thmx";this is a space-delimited list
$destination = @MyDocumentsDir & "\My Dropbox\Document Backup\";location where you'd like your MS Office files backed up.
$index_location = @MyDocumentsDir & "\magus\"
$parent_directory = "c:\Users\";Only the parent directory and its subdirectories will be indexed.
;---------------------------------------------

$file_formats = StringSplit($extension_list, " ")
Global $PID[$file_formats[0] + 1]
$idleticks = $idle_time_in_minutes * 60 * 1000
$max_bytes = $max_size_in_MB * 1000000

ProcessSetPriority(@AutoItPID, 1)

For $i = 1 to $file_formats[0];EDIT: this only runs the initial search if necessary
    If NOT FileExists($index_location & $file_formats[$i] & "_list.txt") Then _SearchForFiles()
Next

While 1 
    If _Timer_GetIdleTime() > $idleticks Then _SearchForFiles();Searching For Documents, if idle

    For $i = 1 to $file_formats[0];Uploading recently modified documents
        $lines = _FileCountLines($index_location & $file_formats[$i] & "_list.txt")
        
        For $q = 1 to $lines
            $source = FileReadLine($index_location & $file_formats[$i] & "_list.txt", $q)
            
            If FilegetSize($source) < $max_bytes Then
                $source_path = StringTrimLeft($source, StringLen($parent_directory))
                For $z = 1 to 80;StringLen($source_path)
                    If StringInStr(StringRight($source_path, $z), "\") Then ExitLoop
                Next
                    
                $source_path = StringTrimRight($source_path, $z - 1)
                $filename = StringTrimLeft($source, (StringLen($source) - $z + 1))

                If FileExists($destination & $source_path & $filename) Then
                    $source_time = FileGetTime($source)
                    $destination_time = FileGetTime($destination & $source_path & $filename)
                    
                    $date_diff = _DateDiff('s', $source_time[0] & "/" & $source_time[1] & "/" & $source_time[2] & " " & $source_time[3] & ":" & $source_time[4] & ":" & $source_time[5], $destination_time[0] & "/" & $destination_time[1] & "/" & $destination_time[2] & " " & $destination_time[3] & ":" & $destination_time[4] & ":" & $destination_time[5])
                                
                    If $date_diff < 0 Then FileCopy($source, $destination & $source_path, 9)
                Else
                    FileCopy($source, $destination & $source_path, 9)
                EndIf
            EndIf
            Sleep($auto_backup_cycle / $file_formats[0] / $lines * 1000 * 60)
        Next
        Sleep(500)
    Next
    Sleep(1000)
WEnd

Func _SearchForFiles()
    For $i = 1 to $file_formats[0]
        $PID[$i] = Run(@comspec & ' /c dir ' & $parent_directory & '"*.' & $file_formats[$i] & '" /b/oN/s > "' & $index_location & "*" & $file_formats[$i] & '_list.txt"', "", @SW_HIDE);EDIT: added "*" wildcard after index_location
        ProcessSetPriority ($PID[$i], 0)
    Next

    For $i = 1 to $file_formats[0];Waiting for all the command processors to close
        ProcessWaitClose($PID[$i])
    Next
EndFunc

If you find a bug, post as many details as you can here, and I'll try to fix it.

Edited by magus

Share this post


Link to post
Share on other sites



I will try this, and let you know how it went.


[font="Lucida Console"]The truth is out there[/font]

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
Sign in to follow this  
Followers 0