Skip to content

Commit e4e3116

Browse files
authored
Create COntainer&VolumeBackup
1 parent 19f9c03 commit e4e3116

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Docker/COntainer&VolumeBackup

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Backup the data volume from the data container named data-container-to-backup
2+
3+
docker run --rm --volumes-from data-container-backup --name tmp-backup -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /folderToBackup
4+
Expand this tar file into a new container so we can commit it as part of its image
5+
6+
docker run -d -v $(pwd):/backup --name data-backup ubuntu /bin/sh -c "cd / && tar xvf /backup/backup.tar"
7+
Commit and push the image with a desired tag ($VERSION)
8+
9+
docker commit data-backup repo/data-backup:$VERSION
10+
docker push repo/data-backup:$VERSION
11+
Finally, lets clean up
12+
13+
docker rm data-backup
14+
docker rmi $(docker images -f "dangling=true" -q)
15+
Now we have an image named data-backup in our repo that is simply a filesystem with the backup files and folders. In order use this image (aka restore from backup), we do the following:
16+
17+
Run the data container with the data-backup image
18+
19+
run -v /folderToBackup --entrypoint "bin/sh" --name data-container repo/data-backup:${VERSION}
20+
Run your whatEver image with volumes from the data-conainter
21+
22+
docker run --volumes-from=data-container repo/whatEver
23+
Thats it.

0 commit comments

Comments
 (0)