Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Source/SvnBackup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using SvnTools;
using SvnTools.CommandLine;

Expand All @@ -10,8 +10,14 @@ namespace SvnBackup
{
class Program
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));

static int Main(string[] args)
{

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

Log.Info("Current Dir:" + Environment.CurrentDirectory);
if (Parser.ParseHelp(args))
{
OutputHeader();
Expand All @@ -34,6 +40,11 @@ static int Main(string[] args)
return 0;
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Log.Fatal("Unhandled exception:" + e.ExceptionObject);
}

private static void OutputUsageHelp()
{
Console.WriteLine();
Expand Down
38 changes: 32 additions & 6 deletions Source/SvnBackup/SvnBackup.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,8 +12,26 @@
<AssemblyName>SvnBackup</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>
</TargetFrameworkSubset>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -37,9 +55,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Libraries\Ionic.Zip.Reduced.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Libraries\log4net.dll</HintPath>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.5\lib\net20-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand All @@ -54,13 +72,21 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SvnTools\SvnTools.csproj">
<Project>{D005FA62-3A70-48B9-B8A7-A7C14AE36774}</Project>
<Name>SvnTools</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions Source/SvnBackup/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.5" targetFramework="net20" />
</packages>
35 changes: 33 additions & 2 deletions Source/SvnTools.Tests/SvnTools.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,26 @@
<AssemblyName>SvnTools.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -31,6 +51,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.4.1\lib\net35\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand All @@ -43,7 +67,6 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework" />
</ItemGroup>
<ItemGroup>
<Compile Include="BackupTest.cs" />
Expand All @@ -62,6 +85,14 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions Source/SvnTools.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.4.1" targetFramework="net35" />
</packages>
14 changes: 8 additions & 6 deletions Source/SvnTools.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvnBackup", "SvnBackup\SvnBackup.csproj", "{9741C214-53FB-4D17-8A3F-391ED8389EA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvnTools.Tests", "SvnTools.Tests\SvnTools.Tests.csproj", "{87E049EB-DC22-4103-8887-294579BED773}"
EndProject
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FF2B4BE8-4601-4C81-8874-7BEBCC71A847}"
ProjectSection(SolutionItems) = preProject
..\Master.proj = ..\Master.proj
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvnBackup", "SvnBackup\SvnBackup.csproj", "{9741C214-53FB-4D17-8A3F-391ED8389EA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvnTools.Tests", "SvnTools.Tests\SvnTools.Tests.csproj", "{87E049EB-DC22-4103-8887-294579BED773}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvnTools", "SvnTools\SvnTools.csproj", "{D005FA62-3A70-48B9-B8A7-A7C14AE36774}"
EndProject
Global
Expand Down
57 changes: 42 additions & 15 deletions Source/SvnTools/Backup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SvnTools
public static class Backup
{
#region Logging Definition
private static readonly log4net.ILog _log = log4net.LogManager.GetLogger(typeof(Backup));
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Backup));
#endregion

/// <summary>
Expand All @@ -24,6 +24,7 @@ public static class Backup
public static void Run(BackupArguments args)
{
var repoRoot = new DirectoryInfo(args.RepositoryRoot);

if (!repoRoot.Exists)
throw new InvalidOperationException(string.Format(
"The repository root directory '{0}' does not exist.",
Expand All @@ -36,6 +37,7 @@ public static void Run(BackupArguments args)
// first try repoRoot as a repository
if (PathHelper.IsRepository(repoRoot.FullName))
BackupRepository(args, repoRoot, backupRoot);

// next try as partent folder for repositories
else
foreach (var repo in repoRoot.GetDirectories())
Expand All @@ -49,7 +51,10 @@ private static void BackupRepository(BackupArguments args, DirectoryInfo reposit
string revString = GetRevision(args, repository);

if (string.IsNullOrEmpty(revString))
{
Log.Info(string.Format("rev string is null in {0}", repository));
return; // couldn't find repo
}

string backupRepoPath = Path.Combine(backupRoot.FullName, repository.Name);
string backupRevPath = Path.Combine(backupRepoPath, revString);
Expand All @@ -58,41 +63,63 @@ private static void BackupRepository(BackupArguments args, DirectoryInfo reposit
if (!Directory.Exists(backupRepoPath))
Directory.CreateDirectory(backupRepoPath);

if (Directory.Exists(backupRevPath) || File.Exists(backupZipPath))
return; // this rev is already backed up
if (File.Exists(backupZipPath))
{
Log.Info(string.Format("this rev is already backed up, dir:{0}", backupRevPath)); // this rev is already backed up
return;
}

// hotcopy
_log.InfoFormat("Backing up '{0}' from '{1}'.", revString, repository.Name);
RunHotCopy(args, repository, backupRevPath);
if (!Directory.Exists(backupRevPath))
{
// hotcopy
Log.InfoFormat("Backing up '{0}' from '{1}'.", revString, repository.Name);
RunHotCopy(args, repository, backupRevPath);
}
else
{
Log.Info(string.Format("this rev is already backed up, dir:{0}", backupRevPath)); // this rev is already backed up
}

// compress
if (args.Compress && !File.Exists(backupZipPath))
if (args.Compress)
{
Log.Info(string.Format("Compressing {0}", backupZipPath));
CompressBackup(backupRevPath, backupZipPath);
}
else
{
Log.Info("compress not active");
}

Log.Info(string.Format("Purging dir {0}", backupRepoPath));
// purge old
PruneBackups(backupRepoPath, args.History);
}
catch (Exception ex)
{
_log.Error(ex.Message, ex);
Log.Error(ex.Message, ex);
}
}

private static void RunHotCopy(BackupArguments args, DirectoryInfo repo, string backupRevPath)
{
var tempDir = backupRevPath + "Temp";

using (var hotCopy = new HotCopy())
{
if (!string.IsNullOrEmpty(args.SubverisonPath))
hotCopy.ToolPath = args.SubverisonPath;

hotCopy.BackupPath = backupRevPath;
hotCopy.BackupPath = tempDir;
hotCopy.RepositoryPath = repo.FullName;

hotCopy.Execute();

if (!string.IsNullOrEmpty(hotCopy.StandardError))
_log.Info(hotCopy.StandardError);
Log.Info(hotCopy.StandardError);
}

Directory.Move(tempDir, backupRevPath);
}

private static string GetRevision(BackupArguments args, DirectoryInfo repo)
Expand All @@ -108,14 +135,14 @@ private static string GetRevision(BackupArguments args, DirectoryInfo repo)

look.Execute();
if (!string.IsNullOrEmpty(look.StandardError))
_log.Info(look.StandardError);
Log.Info(look.StandardError);

if (!look.TryGetRevision(out rev))
{
_log.WarnFormat("'{0}' is not a repository.", repo.Name);
Log.WarnFormat("'{0}' is not a repository.", repo.Name);

if (!string.IsNullOrEmpty(look.StandardOutput))
_log.Info(look.StandardOutput);
Log.Info(look.StandardOutput);

return null;
}
Expand Down Expand Up @@ -152,7 +179,7 @@ private static void PruneBackups(string backupRepoPath, int historyCount)
string dir = dirs[i];

PathHelper.DeleteDirectory(dir);
_log.InfoFormat("Removed backup '{0}'.", dir);
Log.InfoFormat("Removed backup '{0}'.", dir);
}
}

Expand All @@ -164,7 +191,7 @@ private static void PruneBackups(string backupRepoPath, int historyCount)
string file = files[i];

File.Delete(file);
_log.InfoFormat("Removed backup '{0}'.", file);
Log.InfoFormat("Removed backup '{0}'.", file);
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions Source/SvnTools/BackupArguments.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using SvnTools.CommandLine;
using SvnTools.CommandLine;

// $Id$

Expand Down
Loading