<p>I wrote a <strong>CronJob</strong> that periodically takes volume snapshot of my <strong>PVC</strong>. Below is the <strong>CronJob</strong> file:</p>
<pre><code>kind: CronJob
metadata:
  name: mycronjob
spec:
  schedule: &quot;*/2 * * * *&quot;   # Run the job every 2 minutes
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: webserver-container
            image: kubectl:latest
            command:
            - /bin/sh
            - -c
            - /app/script.sh
            volumeMounts:
            - name: script-volume
              mountPath: /app
          restartPolicy: OnFailure
          volumes:
          - name: script-volume
            configMap:
              name: script-configmap
</code></pre>
<p>The <strong>Volume Snapshot</strong> file looks like this:</p>
<pre><code>kind: VolumeSnapshot
metadata:
  name: snap-shot-test
spec:
  volumeSnapshotClassName: csi-snapclass
  source:
    persistentVolumeClaimName: my-test-apps
</code></pre>
<p>And here is the <strong>script</strong> file:</p>
<pre><code>#!/bin/bash
kubectl apply -f volumesnapshot.yml
</code></pre>
<p>First time the cronjob is successfully executed, but after that it says
<em>volumesnapshot.snapshot.storage.k8s.io/snap-shot-test unchanged</em></p>
<p>How can I periodically take volumesnapshot of a PVC with having latest 2 copies of the snapshot?</p>

<p>It seems to me that what you describe mirrors the YAML files you shared; there is nothing that changes the name of the backup and therefore it will never create a new one.</p>
<p>If you want to make a backup of one PVC to another in a &quot;raw&quot; way with scripts, maybe think of a job that mounts 2 Volumes (source and destination) and executes a simple <code>cp -Rp /volume-source/* /volume-destination/</code></p>
<p>Otherwise, if you want to get the job done right, consider using a tool like Velero.</p>
<p><a href="https://velero.io/" rel="nofollow noreferrer">https://velero.io/</a></p>
