Skip to content

Instantly share code, notes, and snippets.

@silviaclaire
Last active May 23, 2018 06:43
Show Gist options
  • Save silviaclaire/34c30194590eed78308195d18beed245 to your computer and use it in GitHub Desktop.
Save silviaclaire/34c30194590eed78308195d18beed245 to your computer and use it in GitHub Desktop.
Linux: Backup directory structure
#!/bin/bash
# (https://superuser.com/questions/1095234/bash-script-to-backup-and-restore-directory-structure)
# create a tar file <Directory_Structure.tar> of the directory structure
# and a list of files <File_List.txt>
# in PWD
HomeDir=$(pwd)
BackupDIR="Backup" # Change here
TarFileName="$HomeDir/Directory_Structure.tar"
ListFileName="$HomeDir/File_List.txt"
cd "$BackupDIR"
tar -cf "$TarFileName" --no-recursion --files-from <(find . -type d)
find . -type f -exec echo touch \"{}\" \; > "$ListFileName"
gzip --best "$ListFileName" "$TarFileName" # this to compress them
#!/bin/bash
tar -zxf Directory_Structure.tar.gz
zcat File_List.txt.gz | /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment