0
#!/bin/bash

source_folder=/samba

target_folder=~/.snapshot/$(date +"%d-%m-%Y")

mkdir -p ~/.snapshot/$(date +"%d-%m-%Y") 

cd $source_folder

cp -r --preserve=ownership,mode  $source_folder/* $target_folder  

sudo find ~/.snapshot -type d -mtime +7 -exec rm -rf {} +;
Léa Gris
  • 17,497
  • 4
  • 32
  • 41
  • Please add more info on the folder or rules defining the folders to exclude, as well as some explanation on the lines of code you pasted. This is your first post, so the community will be more lenient, but you should really have a good read on [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Léa Gris Oct 04 '20 at 12:30

1 Answers1

0

Assuming odd_one is the name of directory you want to exclude, you can do :

shopt -s extglob
cp -r --preserve=ownership,mode  $source_folder/!(odd_one) $target_folder

As you use a normal use to write into ~/.snapshot, you should not use sudo to do rm.

Philippe
  • 20,025
  • 2
  • 23
  • 32