Rsync copying current directory with name

I like your script but, if needed, you can do it by command line directly from the current directory:

rsync -a "$PWD" ~/backup/

or in a way similar to your script approach with

rsync -a "$(pwd -P)" ~/backup/

Notes:

  • It is needed to quote the current directory if in the path is present, for example, one or more spaces.

  • In case of symbolic links in the path it is possible to obtain the physical path avoiding all the symlinks specifying the option -P in the pwd command invocation ($(pwd -P)), or calling the executable with its full path ($(/bin/pwd)).
    Indeed there exists the built-in pwd that by default shows the symlinked path, and the executable /bin/pwd that by default shows the physical path.

  • Both commands refer to the variable $PWD that contains the the present working directory when they are asked for the version of the path with the eventual symlinks: so if you do not strictly need the physical path, you can avoid to call the subshell and use directly the variable $PWD.

    rsync -a "$PWD" ~/backup/
    

Found a solution:

Created a new shell script like this:

current_dir=`pwd`
dir_name=`basename $current_dir`
rsync -a . ~/backup/$dir_name

and when executing this it will create a new directory at the destination and copy current folder contents.