Richard Stallman Explains Everything https://www.youtube.com/watch?v=jUibaPTXSHk # - - # # - crontab with date & time - # http://serverfault.com/questions/117360/sending-cron-output-to-a-file-with-a-timestamp-in-its-name 0 0 * * * /some/path/to/a/file.php > $HOME/`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1 0 0 * * * /some/path/to/a/file.php > $HOME/scriptname-date +\%Y\%m\%d\%H\%M\%S.log # - - # # - In the bash file - # Try this - Add this right below your timestamp function - modified with the proper path, of course. DIRNAME=/path/to/directory LOGFILE=logfile.log cd ${DIRNAME} echo $(timestamp) >> ${LOGFILE} crontabs are run in a different environment than the default shell, so you can use a small shell script under your home directory with something like this in it (we'll name it script.sh): #!/bin/bash php /mix/dostuff.php > /tmp/dostuff-`date +%Y-%m-%H\ %k:%M:%S`.txt exit 1 * * * * root php /mix/dostuff.php > "/tmp/dostuff-`date +\%Y-\%m-\%H\ \%k:\%M:\%S`.txt" # - - # # - Backup & bash of folders & files - # # - Documentation - # # - - # # - Bash files - # # - 1. Create file.sh - # gedit backup.sh # - - # # - 2. Write file's content - # # - First line is very important - It has to be there - # #!/bin/bash #Purpose = Sync backup files to an another server #START # rsync -a --bwlimit=5000 -e ssh --hard-links --inplace sourcefolder destinationuser@example.com:/home/username/full-backup rsync -azvv /home/is_derayo/Documents/R & R Professional Construction, LLC/ is_derayo@isdevelopment.us:/home/is_derayo/Documents/uServerHome/home/Data-1/Images/Backup/uServerOffice-Backup/R & R Professional Construction, LLC/ #END # - - # # - 3. Write file's content - # chmod +x backup.sh sudo chmod +x backup.sh # - File has to be - # rwxr-xr-x # - 4. run the file - # sh ./backup.sh sh backup.sh sh ./backup-rsync_RRProfessionalConstructionLLC.sh sh backup-rsync_RRProfessionalConstructionLLC.sh # - - # # - Backup of folders & files - # # - Documentation - # Put this stuff in a file name "backup-DateTime.sh": #!/bin/bash #Purpose = Sync backup files with date + time echo "Hello! HOME="$HOME echo " PWD=" $PWD now=$(date +%y.%m.%d_%H.%M.%S) echo "The time is " $now # - - # # - BackupYourSystem/TAR - # https://help.ubuntu.com/community/BackupYourSystem/TAR tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system / tar -cvpzf /home/AllDisks-Data/.Backup/SidneyJason-Documents-Backup.tar.gz /home/AllDisks-Data/Documents/SidneyJason-Documents/ tar -cvpzf /home/AllDisks-Data/.Backup/Building-NJ_2175-Lemoine-Ave-Backup.tar.gz /home/AllDisks-Data/Documents/Building-NJ_2175-Lemoine-Ave/ tar -cvpzf /home/Data/Backup/AsusLaptop-R\ \&\ R\ Professional\ Construction\,\ LLC-Backup.tar.gz /home/Data/Documents/R\ \&\ R\ Professional\ Construction\,\ LLC/ # - - # # - rsync - # https://help.ubuntu.com/community/rsync # - 1 - # # - Install rsync - # sudo apt install rsync # - 2 - # # - Run command - # # - Backup SidneyJason-Documents - # rsync -azvv /home/AllDisks-Data/Documents/SidneyJason-Documents/ /home/AllDisks-Data/.Backup/SidneyJason-Documents/ sudo rsync -azvv /home/AllDisks-Data/Documents/SidneyJason-Documents/ /home/AllDisks-Data/.Backup/SidneyJason-Documents/ # - Backup Building-NJ_2175-Lemoine-Ave - # rsync -azvv /home/AllDisks-Data/Documents/Building-NJ_2175-Lemoine-Ave/ /home/AllDisks-Data/.Backup/Building-NJ_2175-Lemoine-Ave/ sudo rsync -azvv /home/AllDisks-Data/Documents/Building-NJ_2175-Lemoine-Ave/ /home/AllDisks-Data/.Backup/Building-NJ_2175-Lemoine-Ave/ Minutes Hours Day of Month Month Day of Week Command 0 to 59 0 to 23 1 to 31 1 to 12 0 to 6 Shell Command Minutes Hours Day of Month Month Day of Week Command 0 to 59 0 to 23 1 to 31 1 to 12 0 to 6 Shell Command # M H DOM M DOW CMND 01 13 * * 1,6 /bin/bash /backup.sh # M H DOM M DOW CMND 30 3 * * * sh /home/srvlinux01/MySQLBackups/backup.sh # M H DOM M DOW CMND 01 13 * * 1,6 /bin/bash /backup.sh #M H DOM M DOW Cmd 30 03 29 02 * /bin/bash /scripts/delete_temp_files.sh M - Minutes H - Hours DOM - Day Of Month M - Month DOW - Day Of Week CMND - Command # - - # # - See crontab status - # /etc/init.d/cron status # - Display crontab file - # crontab -l crontab -lu is_derayo # - Restart crontab service - # /etc/init.d/cron start sudo /etc/init.d/cron start sudo service cron start /etc/init.d/cron stop sudo /etc/init.d/cron stop sudo service cron stop /etc/init.d/cron restart sudo /etc/init.d/cron restart sudo service cron restart # - - # # - Start the cron service at boot time - # # - use the following commands to ensure that the service remains enabled after a reboot - # rcconf sudo rcconf # - You can use command line tool update-rc.d - # update-rc.d cron defaults sudo update-rc.d cron defaults # - - # # - uServerOffice crontab file working just fine - # # - - # # - Edit file - # # - crontab -e - # # - - # # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command 59 23 * * * sh /usr/local/bin/backup-rsync_BuildingNJ-Documents.sh # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 00 1 * * * root /bin/bash /backup-rsync_BuildingNJ-Documents.sh 23 23 * * * root /bin/bash /backup-rsync_BuildingNJ-Documents.sh # - - # # - Configuring crontab - # https://help.ubuntu.com/community/CronHowto http://askubuntu.com/questions/28995/setup-cron-weekly-backup http://broexperts.com/how-to-backup-files-and-directories-in-linux-using-tar-cron-jobs/ http://askubuntu.com/questions/28995/setup-cron-weekly-backup # - Simple backup system for Linux with Bash, Tar, Rsync and Crontab pt.1/2 - # http://tuukkamerilainen.com/simple-backup-system-for-linux-with-bash-tar-rsync-and-crontab-pt-12/ # - - # # - Download and extract the scripts - # wget http://tuukkamerilainen.com/files/backup.tar.gz tar -xf backup.tar.gz http://askubuntu.com/questions/264607/bash-script-not-executing-from-crontab I have the following bash script: #!/bin/bash mysqldump -u ******** -p******** --all-databases | gzip > /home/srvlinux01/MySQLBackups/database_$(date +\%Y-\%m-\%d).sql.gz which is located in /home/srvlinux01/MySQLBackups/ as backup.sh with the following permissions -rwxr--r-- 1 root root 134 feb 27 12:48 backup.sh I've set up a cronjob on sudo crontab -e to run it every day, at night #Automatic MySQL backup # SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin 30 3 * * * sh /home/srvlinux01/MySQLBackups/backup.sh Documentation: https://help.ubuntu.com/community/rsync Introduction From the man page: Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use. In other words, rsync is a tool for efficiently copying and backing up data from one location (the source) to another (the destination). It is efficient because it only transfers files which are different between the source and destination directories. Rsync Rsync is a command line utility. Users attempting to use it should be familiar with the command line (see Using the Terminal). If you prefer a graphical interface, see the Grsync section of this page. Installation Rsync is installed in Ubuntu by default. Be sure to check whether the following packages are installed before starting (see Installing a Package): rsync, xinetd, ssh. Perform a Simple Backup The simplest method for backing up over a network is to use rsync via SSH (using the -e ssh option). Alternatively, you can use the rsync daemon (see Rsync Daemon which requires much more configuration. Local backup only requires rsync and read/write access to the folders being synchronized. Below you will find examples of commands that can be used to backup in either case. It should be noted, that a network sync can be performed locally so long as the folder is shared (say by Samba) and then mounted to the machine with folder1. This process gets around having to use ssh but is less secure and should only be used in secure private networks, like at your home. Local Backup sudo rsync -azvv /home/path/folder1/ /home/path/folder2 Backup Over Network sudo rsync --dry-run --delete -azvv -e ssh /home/path/folder1/ remoteuser@remotehost.remotedomain:/home/path/folder2 An explanation of above options to commands: --dry-run This tells rsync to not actually do anything. It will just write a log of what it would do to the screen. Once you've made sure everything will work as you expect, you have to remove this option, and run the command again to perform the actual backup. --delete deletes files that don't exist on the system being backed up.(Optional) -a preserves the date and times, and permissions of the files (same as -rlptgoD). With this option rsync will: Descend recursively into all directories (-r), copy symlinks as symlinks (-l), preserve file permissions (-p), preserve modification times (-t), preserve groups (-g), preserve file ownership (-o), and preserve devices as devices (-D). -z compresses the data -vv increases the verbosity of the reporting process -e specifies remote shell to use /folder1 and folder2 In the examples above, folder1 and 2 are placeholders for the directories to be synchronized. Folder1 is the original folder, and 2 is the new folder, or existing one to be brought in sync with the first. Replace them with the folders you'd like. A / was added after folder1 so that only the contents, rather than whole folder, would be moved into the second. A complete synopsis of all the options with the rsync command can be found in the man pages under "Options Summary". The man page for rsync can also be found on linux.die.net