Results 1 to 7 of 7

Thread: [SOLVED] Looking for help to backup with cp, but exclude hidden files

  1. #1
    Join Date
    Feb 2006
    Location
    North Carolina, USA
    Beans
    410
    Distro
    Ubuntu

    [SOLVED] Looking for help to backup with cp, but exclude hidden files

    Friends,

    I am trying to create a script for use with multiple users on my Ubuntu system. I want to use cp, essentially in this way:

    Code:
    cp -rup /home/user1 /media/BACKUP/user1
    cp -rup /home/user2 /media/BACKUP/user2
    cp -rup /home/user3 /media/BACKUP/user3
    ...
    If I can lick my problem, I'll write a small shell script and call it from cron. My problem is that when I use cp -rup, it backs up all the hidden files in the users' home directories, such as the ones that begin with a period. I don't want to back up things like .bash_history or any of the program configurations -- I just want data files.

    Has anyone figured this out? I've tried searching through the forum for people doing this another way, say, with rsync -- but I couldn't find what I was looking for...


    Edit 2006-10-30: I forgot to mention, I can certainly do what I'm after by dragging and dropping the files via nautilus; it's just that I want to script this activity...
    Last edited by bswilson; October 30th, 2006 at 03:37 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Stockholm, Sweden
    Beans
    22
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Looking for help to backup with cp, but exclude hidden files

    I use rsync on all of home like this:
    sudo rsync -a -u --progress home /media/SEA_DISC

    Take a look at man of rsync and look for the --exclude option that would give you what you are after I think.

    Good luck
    Jonas

  3. #3
    Join Date
    Feb 2006
    Location
    North Carolina, USA
    Beans
    410
    Distro
    Ubuntu

    Re: Looking for help to backup with cp, but exclude hidden files

    Thanks so much, rydow! I have been able to create a script that works, thanks to your tip on using rsync. My external USB hard drive is mounted as /media/BACKUP, so here's my script:

    Code:
    rsync -a -u --exclude="- *." /home/ /media/BACKUP
    This basically backs up all my family's home directories to my USB drive. The other flags preserve ownership, dates, permissions, etc. (-a) and only copy files that are newer than the destination (-u). The last flag (--exclude="- *.") tells rsync not to copy any file that begins with a dot.

    Thanks!

  4. #4
    Join Date
    Oct 2006
    Beans
    148
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Looking for help to backup with cp, but exclude hidden files

    Quote Originally Posted by bswilson View Post
    Thanks so much, rydow! I have been able to create a script that works, thanks to your tip on using rsync. My external USB hard drive is mounted as /media/BACKUP, so here's my script:

    Code:
    rsync -a -u --exclude="- *." /home/ /media/BACKUP
    This basically backs up all my family's home directories to my USB drive. The other flags preserve ownership, dates, permissions, etc. (-a) and only copy files that are newer than the destination (-u). The last flag (--exclude="- *.") tells rsync not to copy any file that begins with a dot.

    Thanks!

    You can also create a file containg the list of excluding patterns. This is quite powerful! check the man pages!
    Cheers,
    M

  5. #5
    Join Date
    Mar 2005
    Beans
    Hidden!

    Re: Looking for help to backup with cp, but exclude hidden files

    rsnapshot is even better than rsync because it allows for multiple backups from daily, weekly to even monthly. And it uses the rsync/diff method which means that having daily and weekly backups will NOT use up a lot more space than having just one backup. Only new files will take up extra space. Very useful when, for example, a file is required that was deleted a week prior.

    Use rsnapshot with cron and have daily, weekly and monthly backups automated.
    STOP!
    Before you sign up to Dropbox, click here to read my post showing you how to get an additional 500mb free! That's 2.5GB of free space!

  6. #6
    Join Date
    Oct 2006
    Beans
    148
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Looking for help to backup with cp, but exclude hidden files

    Well done! excellent!

    It uses rsync in fact
    As well with hard links - this prevent to duplicate disk space. This is native in the OS but for some reason few is using it!
    Something quite simple but still inexisting under other OS,...

  7. #7
    Join Date
    Oct 2007
    Location
    BCN
    Beans
    26

    Wink Re: [SOLVED] Looking for help to backup with cp, but exclude hidden files

    why do you use --exclude="- *." instead of --exclude=".*" ? as I read it , it excludes all the files ending with a dot not the ones beginning with a dot. moreover the - is not necessary as you already specified the exclude option
    Last edited by babounours; October 24th, 2007 at 11:29 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •