Make archives of stuff that's important in my home directory and recent changes

Forum Forums General Tips and Tricks Make archives of stuff that's important in my home directory and recent changes

  • This topic has 0 replies, 1 voice, and was last updated Jan 27-7:03 am by BobC.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #5887
    Moderator
    AvatarBobC

    Of course my definition of important does matter, ie you might want different things to be considered important enough to save…

    Anyway, maybe this code will be useful for others after a little tweaking. I would suggest creating the archives somewhere not on the partition you are archiving, because /media is excluded from the archive…

    PS: I do not pretend to be any kind of guru on this system, so if you are and see something done poorly here, please speak up.
    PSS: It wasn’t working right, took many hours to fix because tar doesn’t work the same everywhere, and excluding folders via prune on the find isn’t easy unless you have a template where its obvious if things are right or not.

    #!/bin/sh
    
    # rename this file to .sh before you try to edit it, and remember to chmod +x so you can execute it
    
    archiveto="/media/13-Saves2/delldv9917/"
    homedir="/home/bobc"
    # include date in archive filename
    today=<code>date '+%Y_%m_%d__%H_%M_%S'</code>;
    homefilename="home_$today.tgz"
    archivetofileslist="$archiveto.files.list"
    allmodfilename="allmod_$today.tgz"
    homeexcludes="--exclude=$homedir/Downloads --exclude=$homedir/.local/trash"
    
    # archive all important stuff from home directory to archive directory in zipped tar file except Downloads and .cache and .local/trash
    
    tar -zcvf $archiveto$homefilename $homeexcludes --exclude-caches-all $homedir/* 
    
    # archive all stuff I might have changed in last 30 days from / /media/13-Saves2/delldv9917/allmod_2018_01_27.tgz
    
    find / \( \
    	-path /media -prune -o \
    	-path /mnt -prune -o \
    	-path /run -prune -o \
    	-path /sys -prune -o \
    	-path /proc -prune -o \
    	-path /var -prune -o \
    	-path /lib -prune -o \
     	-path /usr/lib -prune -o \
    	-path /root/.cache -prune -o \
    	-path /home/bobc/Downloads -prune -o \
    	-path /home/bobc/.local/trash -prune -o \
    	-path /home/bobc/.cache -prune \) -o -type f -mtime -30 -print > $archivetofileslist
    
    tar -zcvf $archiveto$allmodfilename --exclude-caches-all --files-from=$archivetofileslist
    
    • This topic was modified 3 years, 2 months ago by BobC.
    • This topic was modified 3 years, 2 months ago by BobC.
    • This topic was modified 3 years, 2 months ago by BobC.
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.