Guest User

Untitled

a guest
Aug 14th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. Compressing single file instead of whole directory
  2. #!/bin/sh
  3.  
  4. # Where to backup to.
  5. mkdir -p /home/knoppix/backups --verbose
  6. dest="/home/knoppix/backups"
  7.  
  8. # What to backup.
  9. cat /etc/passwd >> /home/knoppix/backups/dbusers.txt
  10. backupdb="/home/knoppix/backups/dbusers.txt"
  11.  
  12. # Create archive filename.
  13. archive_file="DB$(date +%d%b%Y_%H%M).tgz"
  14.  
  15. # Print start status message.
  16. echo "Backing up $backupdb to $dest/$archive_file"
  17. date
  18. echo
  19.  
  20. # Backup the files using tar.
  21. tar czf $dest/$archive_file $backupdb
  22.  
  23. #!/bin/sh
  24.  
  25. # Where to backup to.
  26. mkdir -p /home/knoppix/backups --verbose
  27. dest="/home/knoppix/backups"
  28.  
  29. # What to backup.
  30. cat /etc/passwd >> /home/knoppix/backups/dbusers.txt
  31. backupdir="/home/knoppix/backups"
  32. backupfile="dbusers.txt"
  33.  
  34. # Create archive filename.
  35. archive_file="DB$(date +%d%b%Y_%H%M).tgz"
  36.  
  37. # Print start status message.
  38. echo "Backing up $backupdb to $dest/$archive_file"
  39. date
  40. echo
  41.  
  42. # Backup the files using tar.
  43. tar czf $dest/$archive_file -C $backupdir $backupfile
  44.  
  45. #!/bin/sh
  46.  
  47. # Where to backup to.
  48. mkdir -p /home/knoppix/backups --verbose
  49. dest="/home/knoppix/backups"
  50.  
  51. # What to backup.
  52. cat /etc/passwd >> /home/knoppix/backups/dbusers.txt
  53. backupdir="/home/knoppix/backups"
  54. backupfile="dbusers.txt"
  55.  
  56. # Create archive filename.
  57. archive_base_name="DB$(date +%d%b%Y_%H%M)"
  58. archive_file="$archive_base_name.tgz"
  59.  
  60. # Print start status message.
  61. echo "Backing up $backupdb to $dest/$archive_file"
  62. date
  63. echo
  64.  
  65. # Backup the files using tar.
  66. tar --transform="s#^$base#$archive_base_name#" czPf $dest/$archive_file $backupdb
  67.  
  68. DB11Nov2011_0555/dbusers.txt
  69.  
  70. tar --transform="s#dbusers#original#" xzf example.tgz # creates original.txt
  71. tar --transform="s#^#output/#" xzf example.tgz # creates output/dbusers.txt
  72.  
  73. $ set -x
  74. $ archive_file="DB$(date +%d%b%Y_%H%M).tgz"
  75. ++ date +%d%b%Y_%H%M
  76. + archive_file=DB11Nov2011_0605.tgz
  77. $ echo $archive_file
  78. + echo DB11Nov2011_0605.tgz
  79. DB11Nov2011_0605.tgz
  80. $ set +x
  81. + set +x
  82. $ echo $archive_file
  83. DB11Nov2011_0605.tgz
  84.  
  85. # Backup the files using tar.
  86. (cd /home/knoppix/backups/; tar czf $dest/$archive_file dbusers.txt)
Add Comment
Please, Sign In to add comment