Advertisement
OldManRiver

dpkg_backup.sh

May 21st, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #! /bin/bash
  2. # Author: Nyle Davis Created 12-05-16
  3. # Purpose: Backup all installed package or Recover from backup
  4. # File: dpkg_backup.sh
  5. # Run this with command:
  6. # sudo bash ../Scripts/Backups/dpkg_backup.sh (options:
  7. # 1=mode=:backup, restore
  8. # 2=default, network or backup path)
  9. echo "DPkg Backup Processing Started! ";
  10.  
  11. # Declare files and dirs
  12. $b_pth="/backups/Laptops/Aspire/";
  13. flname="${b_pth}/dpkg_backup_("`eval date +%Y-%m-%d`").txt";
  14. trname="${b_pth}/dpkg_backup_("`eval date +%Y-%m-%d`").tgz";
  15. ispath='/home/files/Installer Packages/dpkg-installs';
  16. # sc_pth="/home/ndavis/myfiles/Scripts/Backups"; Primary Path (from Aspire)
  17. sc_pth="/Scripts/Backups"; # Secondary Path (from DT)
  18.  
  19. # Get arguments
  20. if [ "${b_pth}" != "/backups/Laptops/Aspire/" ]; then
  21. run_type=$1;
  22. cd "${path}";
  23. if [ ${2} = "default" ]; then
  24. path='/backups/Laptops/Aspire';
  25. elif [ ${2} = "network" ]; then
  26. path='/mnt/New_DT/backups/Laptops/Aspire';
  27. elif [ ${2} != "" ]; then
  28. path=${2};
  29. elif [ $1 = "" & $2 = "" ]; then
  30. echo "No option chosen! ";
  31. exit;
  32. fi
  33. else
  34. run_type="backup";
  35. path=${b_pth};
  36. fi
  37.  
  38. # Run DPKG capture for all currently installed apps
  39. echo "Backing Up DPKG Apps! ";
  40. cd "${path}";
  41. if [ ${run_type} = "backup" ]; then
  42. rm -f ${flname};
  43. dpopt='--get-selections';
  44. dpkg ${dpopt} > ${flname};
  45. tar -czf ${trname} ${flname};
  46. rm -f ${flname};
  47. elif [ ${run_type} = "restore" ]; then
  48. dpopt='--set-selections';
  49. res_opts='& dselect install';
  50. dpkg ${dpopt} < ${flname} ${res_opts};
  51. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement