2

I want to make a backup, but without the symlinks. 7zip has symlinks option for tar and wim.

"Store symbolic links" checked or unchecked to omit them?

Edit: I'm using "add to archive" from the context menu. I want just the files which are physically present in the directory I want to backup. I don't need the files/directories which are linked with symlink.

2 Answers 2

1

In GUI, if you use Add to Archive, there will be checkboxes for only .tar and .wim files (I don't understand why they did not do for .zip, .7z and others) :-(

We have to show some creativity. We can create an exclusion file containing all symbolic links. First open Command Prompt and run cd "Folder" where Folder is the folder location. Now run dir /al /s /b >exclusions.txt. The /s switch is for recursive, you can omit it if not needed. Assuming 7z.exe is in your PATH, then run 7z a "name.7z" "folder\" -xr@exclusions.txt where "Name" is the archive name and "folder" is the folder name. If 7z.exe is not in PATH, you have to specify the full path.

To make the whole process more flex, you can add a context menu entry:

  • First create a batch file with this code:
@echo off
dir /al /b /s %1 >exclusions.txt 2>nul
"C:\Program Files (x86)\7-zip\7z.exe" a "%~na.7z" "%~1\" -xr@exclusions.txt >nul 2>&1
del /f /q exclusions.txt

Note: you can modify the path of 7z.exe.

  • Open Registry Editor as Administrator.
  • Now go to HKEY_CLASSES_ROOT\Folder\shell.
  • Create a new key named Add to archive without symbolic links 7-zip.
  • Then create a subkey named command.
  • Set the default value of command key to "Full path of the .bat file" "%1".

Then you will find a context menu named "Add to archive without symbolic links 7-zip" when you right click a folder.

By default the archive will be created in current working directory named archive.7z (7z format). A modified script that will ask you for Archive name and format:

@echo off
dir /al /b /s %1 >exclusions.txt 2>nul
set /p a_name=Enter Archive name:
set /p a_fo=Enter archive format(Without extension):
if "%a_fo:~0,1%"=="." set "a_fo=%a_fo:~1%"
"C:\Program Files (x86)\7-zip\7z.exe" a "%a_name%.%a_fo%" "%~1\" -xr@exclusions.txt >nul 2>&1
del /f /q exclusions.txt

Now to make the script beyond helpful, you can read the help documentation and add the options as you need. I will prepare a GUI solution (using .NET WinForms and Powershell) in a few days.

Another one with auto UAC elevation and context menu creation:

goto="Batch" /*
:Admin
@echo off
reg query "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip" >nul 2>&1
if %errorlevel% equ 1 (
  reg add "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip"
  reg add "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip\command" 
  reg add "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip\command" /f /v "(Default)" /t REG_SZ /d "Bat file path %1" %== Replace Bat file path here ==%
)
dir /al /b /s %1 >exclusions.txt 2>nul
set /p a_name=Enter Archive name:
set /p a_fo=Enter archive format(Without extension):
if "%a_fo:~0,1%"=="." set "a_fo=%a_fo:~1%"
"C:\Program Files (x86)\7-zip\7z.exe" a "%a_name%.%a_fo%" "%~1\" -xr@exclusions.txt >nul 2>&1
del /f /q exclusions.txt
exit /b 0
:RunAsAdmin
color 4f & echo Running Admin Shell, Please wait.... & call cscript //nologo /e:JScript "%~f0" RunAsAdmin "%1" & exit /b
:"Batch"
@echo off & setlocal enabledelayedexpansion & cls
openfiles >nul 2>&1 || goto :RunAsAdmin
goto :Admin
:"JScript" */
function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) }
if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName,WSH.Arguments(1));
//
0

"Store symbolic links" checked or unchecked to omit them?

GUI options:

Menu > File > Link ... Create symbolic link or hard link

Command Line Options:

-snl Store symbolic links as links (WIM and TAR formats only)

Source 7Zip Help File (Windows)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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