はじめに
「バックアップと復元」も「ファイル履歴」も非推奨っぽい扱いで、さりとて、推されているOneDriveは使いたくなくて、放浪の末、resticに流れ着きました。
resticは、Goで書かれたオープンソースの「高速、安全、効率的なバックアッププログラム」です。
wbadminを使ったイメージバックアップにも言及します。
この記事は、将来の復元のために個人的なバックアップ構成を記録しておくものです。
前提
- Windows 11 Pro 24H2
- C:System (SSD)、D:Data (SSD)、F:Backup (HDD)
- restic 0.18.1
- restic-browser v0.3.3
方針
イメージのバックアップ
バックアップと復元 (Windows 7) (GUI)の代わりに、wbadmin (CLI)を使用します。
1週間毎に、システムドライブのみ、最新1世代だけ残します。
ファイルのバックアップ
resticを使用します。
時間毎に48時間、日毎に14日間、週毎に9週間、月毎に24ヶ月間を残して、システムドライブのユーザディレクトリとデータドライブの必要なディレクトリをバックアップします。
個別ファイルの復元にはrestic-browserを使用します。
スケジューリング
タスクスケジューラを使用します。
構成
イメージのバックアップ
@echo off
openfiles > nul 2>&1
if %ERRORLEVEL% equ 0 goto pass
rem 【管理者権限がない】
echo Insufficient privileges to perform this action.
echo %DATE% %TIME%>%~dp0\WindowsImageBackup.log 2>&1
echo Insufficient privileges to perform this action. %DATE% %TIME%>%~dp0\WindowsImageBackup.log 2>&1
goto end
:pass
echo %DATE% %TIME%>%~dp0\WindowsImageBackup.log 2>&1
rem echo --- forget ----------->>%~dp0\WindowsImageBackup.log 2>&1
rem wbadmin delete backup -keepVersions:2 -quiet >>%~dp0\WindowsImageBackup.log 2>&1
echo --- backup ----------->>%~dp0\WindowsImageBackup.log 2>&1
wbadmin start backup -backupTarget:f: -allCritical -vssFull -quiet >>%~dp0\WindowsImageBackup.log 2>&1
echo ---------------------->>%~dp0\WindowsImageBackup.log 2>&1
wbadmin get versions >>%~dp0\WindowsImageBackup.log 2>&1
echo %DATE% %TIME%>>%~dp0\WindowsImageBackup.log 2>&1
:end
ファイルのバックアップ
RESTIC_PASSWORD=<パスワード>
RESTIC_REPOSITORY=<リポジトリパス(F:)>
@echo off
openfiles > nul 2>&1
if %ERRORLEVEL% equ 0 goto pass
rem 【管理者権限がない】
echo Insufficient privileges to perform this action.
echo Insufficient privileges to perform this action. %DATE% %TIME%>%~dp0\ResticBackup.log 2>&1
goto end
:pass
echo %DATE% %TIME%>%~dp0\ResticBackup.log 2>&1
echo --- snapshots -------->>%~dp0\ResticBackup.log 2>&1
restic snapshots >>%~dp0\ResticBackup.log 2>&1
echo --- forget ----------->>%~dp0\ResticBackup.log 2>&1
restic forget --keep-hourly 48 --keep-daily 14 --keep-weekly 9 --keep-monthly 24 --prune >>%~dp0\ResticBackup.log 2>&1
echo --- backup ----------->>%~dp0\ResticBackup.log 2>&1
restic backup --use-fs-snapshot %USERPROFILE% d:\path1 d:\path2 d:\path3 >>%~dp0\ResticBackup.log 2>&1
echo --- check ------------>>%~dp0\ResticBackup.log 2>&1
restic check >>%~dp0\ResticBackup.log 2>&1
echo ---------------------->>%~dp0\ResticBackup.log 2>&1
echo %DATE% %TIME%>>%~dp0\ResticBackup.log 2>&1
:end
スケジューリング
イメージバックアップ
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2024-09-16T01:51:34.6212723</Date>
<Author>PC-NAME\UserName</Author>
<Description>システムイメージのバックアップを実施する</Description>
<URI>\WindowsImageBackup</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2024-09-22T19:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByWeek>
<DaysOfWeek>
<Sunday />
</DaysOfWeek>
<WeeksInterval>1</WeeksInterval>
</ScheduleByWeek>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>X-X-X-XX-XXXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-XXXX</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>true</WakeToRun>
<ExecutionTimeLimit>P1D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Users\~\image-backup.bat</Command>
</Exec>
</Actions>
</Task>
ファイルバックアップ
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2023-10-03T16:17:58.562162</Date>
<Author>PC-NAME\UserName</Author>
<Description>1時間毎にResticでバックアップを実行します。</Description>
<URI>\ResticBackup</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<Repetition>
<Interval>PT1H</Interval>
<Duration>P1D</Duration>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2023-10-03T17:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>X-X-X-XX-XXXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-XXXX</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT1M</Duration>
<WaitTimeout>PT45M</WaitTimeout>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>true</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>9</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Users\~\file-backup.bat</Command>
</Exec>
</Actions>
</Task>
ファイルバックアップの監査
方針
月に一度、1/24を読み込みチェックします。
構成
@echo off
openfiles > nul 2>&1
if %ERRORLEVEL% equ 0 goto pass
rem 【管理者権限がない】
echo Insufficient privileges to perform this action.
echo Insufficient privileges to perform this action. %DATE% %TIME%>%~dp0\ResticCheck.log 2>&1
goto end
:pass
echo %DATE% %TIME%>%~dp0\ResticCheck.log 2>&1
echo --- check ------------>>%~dp0\ResticCheck.log 2>&1
restic check --read-data-subset=1/24 >>%~dp0\ResticCheck.log 2>&1
echo ---------------------->>%~dp0\ResticCheck.log 2>&1
echo %DATE% %TIME%>>%~dp0\ResticCheck.log 2>&1
:end
スケジュール
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2025-12-29T15:53:13.1054096</Date>
<Author>PC-NAME\UserName</Author>
<Description>月に一度、resticのリポジトリをチェックします。</Description>
<URI>\ResticCheck</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2025-12-29T13:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByMonthDayOfWeek>
<Weeks>
<Week>1</Week>
</Weeks>
<DaysOfWeek>
<Sunday />
</DaysOfWeek>
<Months>
<January />
<February />
<March />
<April />
<May />
<June />
<July />
<August />
<September />
<October />
<November />
<December />
</Months>
</ScheduleByMonthDayOfWeek>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>X-X-X-XX-XXXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-XXXX</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>true</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Users\~\file-check.bat</Command>
</Exec>
</Actions>
</Task>
復元
イメージ
Windows RE (回復環境)を使用します。
ファイル
restic-browserを使用します。
おわりに
個人的なメモですが、どなたかのお役に立てたなら幸いです。
お気づきの点などあれば、ぜひお知らせください。
どうもありがとうございました。