Advertisement
opexxx

Encrypted_backups

Nov 24th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.06 KB | None | 0 0
  1. Encrypted backups
  2. This document explains how to create and automate encrypted backups on Linux, using standard tools.
  3.  
  4. 1. Prepare an encrypted file system
  5. Create a file of the size of a dvd (make sure there are at least 4.5Gb available on the target filesystem (/opt for instance)
  6.  
  7.  
  8. dd if=/dev/zero of=/opt/encrypted_filesystem bs=1024k count=4489 (for a dvd R)
  9. dd if=/dev/zero of=/opt/encrypted_filesystem bs=1024k count=4450 (dvd RW are a bit smaller)
  10. dd if=/dev/zero of=/opt/encrypted_filesystem bs=1024k count=700 (700 Mb cdrom)
  11.  
  12. Make sure to have the following modules loaded :
  13. (you can also use blowfish or serpent instead of aes - consult /lib/modules/*/kernel/crypto/)
  14.  
  15. modprobe loop
  16. modprobe cryptoloop
  17. modprobe aes
  18.  
  19. Prepare the loop device - you will be prompted for a password :
  20.  
  21. losetup -e aes /dev/loop0 /opt/encrypted_filesystem
  22.  
  23. Format the filesystem
  24.  
  25. mkfs -t ext2 /dev/loop0
  26.  
  27. The following command makes more space available for the data :
  28.  
  29. tune2fs -m 0 /dev/loop0
  30.  
  31. 2. Copy your files to the new encrypted filesystem
  32. The filesystem is now ready and can be mounted by :
  33.  
  34. mount /dev/loop0 /mnt/encrypted
  35.  
  36. The files can be stored on it now:
  37.  
  38. cp ~/* /mnt/encrypted
  39.  
  40. Unmount the encrypted filesystem after that :
  41.  
  42. umount /dev/loop0
  43. losetup -d /dev/loop0
  44.  
  45. 3. Burn the data on a cd/dvd
  46. growisofs -dvd-compat -Z /dev/dvd=/opt/encrypted_filesystem
  47.  
  48. 4. Use your backups when needed
  49. Mount the cd/dvd by :
  50.  
  51. losetup -e aes /dev/loop0 /dev/dvd
  52. mount /dev/loop0 /mnt/cdrom
  53.  
  54. Unmount it once finished :
  55.  
  56. umount /dev/loop0
  57. losetup -d /dev/loop0
  58.  
  59. 5. Create new backups, using the same password
  60. Re-mount the encrypted filesystem created before :
  61.  
  62. losetup -e aes /dev/loop0 /opt/encrypted_filesystem
  63. mount /dev/loop0 /mnt/encrypted
  64.  
  65. Delete the existing files :
  66.  
  67. rm -rf /mnt/encrypted/*
  68.  
  69. Copy the new files :
  70.  
  71. cp -R /usr /mnt/encrypted/
  72.  
  73. Umount the filesystem :
  74.  
  75. umount /dev/loop0
  76. losetup -d /dev/loop0
  77.  
  78. Burn to a dvd (see cdrecord for burning cdroms):
  79.  
  80. growisofs -dvd-compat -Z /dev/dvd=/opt/encrypted_filesystem
  81.  
  82. More info :
  83. man losetup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement