Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a file share, and I want a process which enumerates files on that share and automatically creates a 7z self-extracting exe of files over 1 month old. On a different share, I want to create a 7z self-extracting exe of directories that are over 1 month old. Any idea if there is a program which can do this? I already have

7z a -t7z -mx9 -sfx filename.exe filename.txt 

Portion of it, just need more of the auto-management portion.

Running on Windows Server 2008, yes, PowerShell is available. Cygwin would not be an option.

share|improve this question
    
Which operating system? I'm assuming Windows. If so, do you have access to Powershell? –  Benjamin Anderson Jan 10 '11 at 18:19
    
esac please edit your question qith a little more information about your system. Like Benjamin asked we need to know about operating system and whether you have things like powershell, cygwin, or other tool sets. –  Caleb Jan 10 '11 at 18:59
add comment

2 Answers 2

up vote 1 down vote accepted

I ended up doing this with a batch file, and setting it to run via Task Scheduler. Here is the batch file if anyone is interested:

@echo off

set RETENTION_PERIOD_DAYS=30
set FILE_BASED_ARCHIVES=g:\shares\public\crashes
set DIRECTORY_BASED_ARCHIVES=g:\shares\results
set MINIMUM_FILESIZE=1000000
set ZIP_PATH="c:\Program Files\7-Zip\7z.exe"

if not {%1}=={} call :archive %1 %2 %3 %4&exit /b 0

echo Archiving files older than %RETENTION_PERIOD_DAYS% days.
echo File Based: %FILE_BASED_ARCHIVES%
echo Directory Based: %DIRECTORY_BASED_ARCHIVES%


for %%a in (%FILE_BASED_ARCHIVES%) do (
    echo ********* Archiving %%a
    du /s "%%a"
    echo  -----------------------
    forfiles /p %%a /s /m *.* /d -%RETENTION_PERIOD_DAYS% /c "cmd /c call ^0x22%~dpnx0^0x22 ^0x22FILE^0x22 ^0x22@isdir^0x22 ^0x22@fsize^0x22 @path"
    echo  -----------------------
    du /s "%%a"
    echo ****************************************************
)

for %%a in (%DIRECTORY_BASED_ARCHIVES%) do (
    echo ********* Archiving %%a
    du /s "%%a"
    echo  -----------------------
    forfiles /p %%a /d -%RETENTION_PERIOD_DAYS% /c "cmd /c call ^0x22%~dpnx0^0x22 ^0x22DIR^0x22 ^0x22@isdir^0x22 ^0x22@fsize^0x22 @path"
    echo  -----------------------
    du /s "%%a"
    echo ****************************************************
)



exit /b 0

:archive
    if /i "%~1"=="FILE" (
        if /i "%~2"=="FALSE" (call :archive_file %3 %4) else (echo Skipping %~4 as it is not a file.)
    )
    if /i "%~1"=="DIR" (
        if /i "%~2"=="TRUE" (call :archive_dir %4) else (echo Skipping %~4 as it is not a directory.)
    )
exit /b 0

:archive_file
    set FILESIZE=%~1
    if %FILESIZE% GEQ %MINIMUM_FILESIZE% (
        call :7zip %2 && del /q /f %2
    ) else (
       echo Skipping %~2 as it is smaller than %MINIMUM_FILESIZE% bytes.
    )
exit /b 0

:archive_dir
    call :7zip %1 && rd /q /s %1
exit /b 0

:7zip
    %ZIP_PATH% t "%~1">nul || (
        %ZIP_PATH% a -t7z -mx9 -sfx "%~dp1%~n1.exe" "%~dpnx1" || exit /b 1
    )
exit /b 0
share|improve this answer
add comment

Looks like he's running windows guys. (.exe)

Create a shortcut or batch file that runs the command, and then run the shortcut or batch file from Windows Task Scheduler.

share|improve this answer
1  
That's not a hard-positive indicator as to which operating system being used. Yes, most of the time it is windows, but other operating system don't care what the extension is for executables. Nor does your response actually answer the question. With more information, a real answer could be provided. –  Benjamin Anderson Jan 10 '11 at 22:50
    
My apologies for not reading the question more thoroughly, though it looks like my answer guided him in the right direction. –  goofology Jan 17 '11 at 19:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.