Unique way to backup Perforce Streams
TeamCity config to back up Perforce streams
One thing I always struggled with when it comes to Perforce was backing up the data. With Docker, you can just stop the server, copy the CONFIG_PATH folder and store it somewhere. I did not want to do this because this method also copies revisions of files.
Since I’m a small shop and I don’t foresee myself having to need months of historical revisions, I wanted a method that would just copy the most recent revisions of all of my streams. The steps are a bit specific to my setup since I’m saving the backup on my local file server that will then sync it to Synology C2.
You don’t have to use Windows to do this but I preferred to run this on windows since the setup was more straightforward to me than setting up a NFS client to connect to my file server.
This build is ran inside of the mcr.microsoft.com/windows/servercore:ltsc2022 docker container. Here’s the batch script
net use Z: \\%SERVER_LOCATION%\backups\%ARCHIVE_DIR% /user:%DDC_USER% %DDC_PASS%
tar -czf %system.teamcity.build.tempDir%\%teamcity.build.branch%.tar.gz .
xcopy %system.teamcity.build.tempDir%\%teamcity.build.branch%.tar.gz Z:\ /Y
What this does is mount a network share to Z:. The DDC_USER and DDC_PASS are the username and password of the fileshare that you’re trying to connect to. The tar command will create an archive of the current working directory. The first parameter is the place to store the file and the second command is the folder to create an archive for. The xcopy will then copy the archive to the network share and the /Y switch is to overwrite the file if it already exists
The last thing to do is set up a trigger. Jenkins is a bit annoying with the Perforce plugin that they have. The TeamCity trigger is quite nice, I have this setup to run every Sunday at 12am and it will back up every stream that has any new changes since the last time it was ran.