Document Type | Troubleshooting
Category | Backup/Recovery
Applicable Product Version | 6FS07
Document Number | TBATS009
Issue
When executing the Tibero backup script in a Windows environment, the process fails at the data file copy stage.
Cause
The copy command used within the backup script cannot properly copy data files that have the read-only attribute set, causing the entire backup operation to fail.
Difference Between copy and xcopy
Feature | COPY | XCOPY |
|---|---|---|
Overwrite Read-Only Files | Fails (read-only files cannot be overwritten) | Allows overwrite with /R option |
Overwrite Confirmation Prompt | Automatically prompts for confirmation (interrupts automation scripts) | Overwrites without confirmation using /Y option |
Directory Copy | Supports only single file copy | Can copy subfolders with /S, /E options |
Solutions
When copying data files, change the script to use the xcopy command with both /R and /Y options to allow copying read-only files.
Part of the script changed compared to the original Windows backup script
for /f %%F in (%LIST_DIR%\datafile.list) do ( :: ****Modified part**** - Use `xcopy` for data file copying echo Copying file %%F to backup directory... >> "%LOG%" xcopy "%%F" "%BACKUP_DIR%" /R /Y >> "%LOG%" 2>&1 if errorlevel 1 ( echo ERROR: Failed to copy file %%F >> "%LOG%" ) )
Note
Full Windows Backup Script@echo off setlocal :: Shell Environment set "TB_USER=tibero" set "TB_HOME=C:\Tibero\tibero6" set "ARCH_DIR=C:\Tibero\tbarch" set "WORK_DIR=C:\Tibero\full_backup" set "BACKUP_DIR=%WORK_DIR%\%date:~2,2%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%" set "BACKUP_CTL=%BACKUP_DIR%\control.ctl.bak" set "LIST_DIR=%WORK_DIR%\list" set "TMP_DIR=%WORK_DIR%\tmp" set "LOG_DIR=%WORK_DIR%\log" set "LOG=%LOG_DIR%\%computername%_%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log" set "TABLESPACES=%LIST_DIR%\TABLESPACES.LIST" set "FILE_LIST=%LIST_DIR%\FILES.LIST" set "DB_LIST=%LIST_DIR%\DB.LIST" set "TMP_FILE=%TMP_DIR%\tmp_file.tmp" mkdir "%BACKUP_DIR%" mkdir "%LIST_DIR%" mkdir "%TMP_DIR%" mkdir "%LOG_DIR%" copy nul "%LOG%" :: Check initial directories and log file if not exist "%BACKUP_DIR%" ( echo ERROR !! BACKUP_DIR is not set. Check %BACKUP_DIR% >> "%LOG%" exit /b 1 ) if not exist "%LIST_DIR%" ( echo ERROR !! LIST_DIR is not set. Check %LIST_DIR% >> "%LOG%" exit /b 1 ) if not exist "%TMP_DIR%" ( echo ERROR !! TMP_DIR is not set. Check %TMP_DIR% >> "%LOG%" exit /b 1 ) if not exist "%LOG_DIR%" ( echo ERROR !! LOG_DIR is not set. Check %LOG_DIR% >> "%LOG%" exit /b 1 ) if not exist "%LOG%" ( echo ERROR !! LOG is not set. Check %LOG% >> "%LOG%" exit /b 1 ) :: Delete existing files for /f %%A in ('dir /b "%LIST_DIR%"') do ( del /q "%LIST_DIR%\%%A" echo %LIST_DIR%\%%A deleted >> "%LOG%" ) || ( echo no files to delete at %LIST_DIR% >> "%LOG%" ) for /f %%B in ('dir /b "%TMP_DIR%"') do ( del /q "%TMP_DIR%\%%B" echo %TMP_DIR%\%%B deleted >> "%LOG%" ) || ( echo no files to delete at %TMP_DIR% >> "%LOG%" ) :: Backup Begin echo "################################################################################" >> "%LOG%" echo "##### Backup Begin" >> "%LOG%" echo "##### Begin Time : %date% %time%" >> "%LOG%" echo "##### Datafile backup Begin " >> "%LOG%" ( echo spool %TMP_DIR%\tbs.tmp echo select tablespace_name from dba_tablespaces; echo spool off echo exit ) | tbsql sys/tibero > nul findstr /v /c:"TABLESPACE" /c:"----" /c:"selected" /c:"SQL" %TMP_DIR%\tbs.tmp | findstr /v "^$" > %TMP_DIR%\tbs_l.tmp for /f %%C in (%TMP_DIR%\tbs_l.tmp) do (echo %%C >> %TMP_DIR%\TABLESPACES.TEMP) findstr /v /c:"TEMP" %TMP_DIR%\TABLESPACES.TEMP >> %TABLESPACES% ( echo spool %TMP_DIR%\datafile.tmp echo select file_name from dba_data_files; echo spool off echo exit ) | tbsql sys/tibero > nul findstr /v /c:"FILE" /c:"----" /c:"selected" /c:"SQL" %TMP_DIR%\datafile.tmp | findstr /v "^$" > %TMP_DIR%\df_l.tmp for /f %%D in (%TMP_DIR%\df_l.tmp) do echo %%D >> %LIST_DIR%\datafile.list :: Data file backup for /f %%E in (%TABLESPACES%) do ( ( echo alter tablespace %%E begin backup wait; echo exit ) | tbsql sys/tibero > nul 2>&1 ) for /f %%F in (%LIST_DIR%\datafile.list) do ( :: ****Modified part**** echo Copying file %%F to backup directory... >> "%LOG%" xcopy "%%F" "%BACKUP_DIR%" /Q /R /Y >> "%LOG%" 2>&1 if errorlevel 1 ( echo ERROR: Failed to copy file %%F >> "%LOG%" ) ) for /f %%G in (%TABLESPACES%) do ( ( echo alter tablespace %%G end backup wait; echo exit ) | tbsql sys/tibero > nul ) echo "##### Datafile backup End" >> "%LOG%" :: Archive and Controlfile backup echo "##### Archive and Controlfile backup Begin" >> "%LOG%" ( echo alter system switch logfile; echo alter database backup controlfile to trace as '%BACKUP_CTL%' reuse noresetlogs; echo exit ) | tbsql sys/tibero > nul xcopy /e /i /q "%ARCH_DIR%" "%BACKUP_DIR%" >> "%LOG%" 2>&1 if errorlevel 1 ( echo ERROR: Failed to copy archive logs from %ARCH_DIR% >> "%LOG%" ) echo "##### Archive and Controlfile backup End" >> "%LOG%" echo "##### ALL Backup Complete!!!!" >> "%LOG%" echo "##### End Time : %date% %time%" >> "%LOG%" echo "################################################################################" >> "%LOG%" echo " " >> "%LOG%" endlocal